home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume10 / cbw / part01 next >
Encoding:
Internet Message Format  |  1987-06-16  |  60.6 KB

  1. Path: seismo!uunet!rs
  2. From: rs@uunet.UU.NET (Rich Salz)
  3. Newsgroups: comp.sources.unix
  4. Subject: v10i001:  Crypt Breaker's Workbench, Part01/11
  5. Message-ID: <373@uunet.UU.NET>
  6. Date: 17 Jun 87 22:33:58 GMT
  7. Organization: UUNET Communications Services, Arlington, VA
  8. Lines: 2648
  9. Approved: rs@uunet.uu.net
  10.  
  11. Submitted by: Robert W. Baldwin <BALDWIN@XX.LCS.MIT.EDU>
  12. Mod.sources: Volume 10, Issue 1
  13. archive-name: cbw/Part01
  14.  
  15. #! /bin/sh
  16. # This is a shell archive.  Remove anything before this line, then unpack
  17. # it by saving it into a file and typing "sh file".  To overwrite existing
  18. # files, type "sh file -c".  You can also feed this as standard input via
  19. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  20. # will see the following message at the end:
  21. #        "End of archive 1 (of 11)."
  22. # Contents:  Index MANIFEST Makefile TODO.txt UU.graphics approx.c
  23. #   autotri.h banner.c cblocks.c char-io.c common.words dblock.h
  24. #   dbsaux.c enigma.c h19.slice keylib.c layout.h
  25. #   mss-prob-printout.txt mss.stats mss.words parser.c parser.h
  26. #   pgate.c pqueue.c pqueue.h sdriver.c short.words stats.slice
  27. #   test3.words trigrams.short trigrams.stats tritab.c vt100.slice
  28. #   zeecode.c
  29. # Wrapped by rs@uunet on Wed Jun 17 18:17:00 1987
  30. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  31. if test -f Index -a "${1}" != "-c" ; then 
  32.   echo shar: Will not over-write existing file \"Index\"
  33. else
  34. echo shar: Extracting \"Index\" \(2276 characters\)
  35. sed "s/^X//" >Index <<'END_OF_Index'
  36. XIndex for CBW programs and data files.
  37. X
  38. X
  39. XTemplate:
  40. X
  41. XProgram Name:  
  42. XDescription:   
  43. XBrief Doc:     
  44. XMaintainer:    
  45. XFiles:         
  46. X
  47. X
  48. XPrograms:
  49. X
  50. XProgram Name:  cbw
  51. XDescription:   Interactive code breaker's workbench.
  52. XBrief Doc:     Execute "runcbw", see cbw.doc.
  53. XMaintainer:    Bob Baldwin  (Baldwin@mit-xx) (eddie!baldwin.UUCP)
  54. XFiles:         dblock.h, layout.h, parser.h, specs.h, window.h,
  55. X               banner.c, cblocks.c, dblock.c, dline.c, gblock.c,
  56. X               keylib.c, knit.c, parser.c, screen.c, start.c,
  57. X               stats.c, triglist.c, trigram.c, user.c, webster.c,
  58. X               windowlib.c
  59. X
  60. X
  61. XProgram Name:  enigma
  62. XDescription:   Identical to crypt command based on one-rotor enigma.
  63. XBrief Doc:     enigma <infile >outfile    It will ask for key.
  64. XMaintainer:    Bob Baldwin
  65. XFiles:         enigma.c
  66. X
  67. X
  68. XProgram Name:  zeecode
  69. XDescription:   Zeecode assumes that the file zeecode.perm contains a .perm
  70. X           file produced by cbw.  It uses the A0 and Zee permutations
  71. X           in that file to decode the standard input, printing results
  72. X           on the standard output.
  73. XBrief Doc:     zeecode <cipherfile >cleartextfile
  74. X               Reads zeecode.save to get A0 and Zee.
  75. XMaintainer:    Bob Baldwin
  76. XFiles:         zeecode.c
  77. X
  78. X
  79. X
  80. XData Files:
  81. X
  82. XTemplate:
  83. X
  84. XFile Name:    
  85. XDescription:    
  86. X
  87. X
  88. XFile Name:    *.slice
  89. XDescription:    Pieces of .login file to init CBW shell variables.
  90. X
  91. XFile Name:    graphics
  92. XDescription:    Cat'ing this file displays all the graphics characters
  93. X        on heath and vt100 terminals.
  94. X
  95. XFile Name:    cbw.log
  96. XDescription:    History of changes to cbw source.
  97. X
  98. XFile Name:    cbw.doc and cbw.mss
  99. XDescription:    User manual for cbw.
  100. X
  101. XFile Name:    trigrams.stats
  102. XDescription:    Frequencies of common trigrams.
  103. X
  104. XFile Name:    mss-bigram.stats
  105. XDescription:    Bigram statistics for scribe files. 
  106. X
  107. XFile Name:    mss.stats
  108. XDescription:    Monogram statistics for scribe files. 
  109. X
  110. XFile Name:    *.cipher
  111. XDescription:    Ciphertext file read by cbw.
  112. X
  113. XFile Name:    *.perm
  114. XDescription:    Permutations saved by cbw to record partial solutions
  115. X        to a ciphertext.
  116. X
  117. XFile Name:    *.txt
  118. XDescription:    Original text used to create the .cipher files.
  119. X
  120. XFile Name:    *.words
  121. XDescription:    Lists of words for use with the probable-word guessing
  122. X        strategy.
  123. X
  124. XFile Name:    test3.words
  125. XDescription:    Probable words for test3.cipher.
  126. END_OF_Index
  127. if test 2276 -ne `wc -c <Index`; then
  128.     echo shar: \"Index\" unpacked with wrong size!
  129. fi
  130. # end of overwriting check
  131. fi
  132. if test -f MANIFEST -a "${1}" != "-c" ; then 
  133.   echo shar: Will not over-write existing file \"MANIFEST\"
  134. else
  135. echo shar: Extracting \"MANIFEST\" \(2376 characters\)
  136. sed "s/^X//" >MANIFEST <<'END_OF_MANIFEST'
  137. X   File Name        Archive #    Description
  138. X-----------------------------------------------------------
  139. X Index                     1    
  140. X MANIFEST                  1    
  141. X Makefile                  1    
  142. X Read.me                   5    
  143. X TODO.txt                  1    
  144. X UU.foo                    9    
  145. X UU.graphics               1    
  146. X UU.test                   4    
  147. X UU.test1                  4    
  148. X UU.test2                  3    
  149. X UU.test3                 10    
  150. X approx.c                  1    
  151. X autotri.c                 4    
  152. X autotri.h                 1    
  153. X banner.c                  1    
  154. X bdriver.c                 2    
  155. X cblocks.c                 1    
  156. X cbw.doc                  11    
  157. X cbw.log                   3    
  158. X char-io.c                 1    
  159. X cipher.c                  5    
  160. X cipher.h                  2    
  161. X common.words              1    
  162. X dblock.c                  7    
  163. X dblock.h                  1    
  164. X dbsaux.c                  1    
  165. X dline.c                   4    
  166. X eclass.c                  5    
  167. X edriver.c                 2    
  168. X enigma.c                  1    
  169. X foo.perm                  6    
  170. X gblock.c                  2    
  171. X h19.slice                 1    
  172. X keylib.c                  1    
  173. X knit.c                    5    
  174. X layout.h                  1    
  175. X lpair.c                   6    
  176. X mss-bigram-old.stats      2    
  177. X mss-bigram.stats          3    
  178. X mss-prob-printout.txt     1    
  179. X mss.stats                 1    
  180. X mss.words                 1    
  181. X parser.c                  1    
  182. X parser.h                  1    
  183. X perm.c                    2    
  184. X pgate.c                   1    
  185. X pqueue.c                  1    
  186. X pqueue.h                  1    
  187. X pword.c                   3    
  188. X screen.c                  3    
  189. X sdriver.c                 1    
  190. X short.words               1    
  191. X specs.h                   4    
  192. X start.c                   2    
  193. X stats.c                   8    
  194. X stats.slice               1    
  195. X tdriver.c                 3    
  196. X terminal.c                8    
  197. X terminal.h                2    
  198. X test.txt                  4    
  199. X test1.perm                6    
  200. X test1.txt                 3    
  201. X test2.txt                 2    
  202. X test3.perm                7    
  203. X test3.txt                 9    
  204. X test3.words               1    
  205. X trigrams.short            1    
  206. X trigrams.stats            1    
  207. X tritab.c                  1    
  208. X user.c                    4    
  209. X vt100.slice               1    
  210. X webster.c                 2    
  211. X window.h                  3    
  212. X windowlib.c               2    
  213. X zeecode.c                 1    
  214. X zeecode.perm              5    
  215. END_OF_MANIFEST
  216. if test 2376 -ne `wc -c <MANIFEST`; then
  217.     echo shar: \"MANIFEST\" unpacked with wrong size!
  218. fi
  219. # end of overwriting check
  220. fi
  221. if test -f Makefile -a "${1}" != "-c" ; then 
  222.   echo shar: Will not over-write existing file \"Makefile\"
  223. else
  224. echo shar: Extracting \"Makefile\" \(1573 characters\)
  225. sed "s/^X//" >Makefile <<'END_OF_Makefile'
  226. XCFLAGS = -g
  227. X
  228. X# Object files for for the workbench.
  229. Xcbreq =    pword.o lpair.o approx.o \
  230. X        eclass.o cipher.o char-io.o \
  231. X        tritab.o autotri.o pqueue.o \
  232. X        webster.o user.o gblock.o dblock.o dbsaux.o banner.o \
  233. X        cblocks.o stats.o parser.o knit.o \
  234. X        pgate.o perm.o terminal.o \
  235. X        keylib.o windowlib.o dline.o screen.o 
  236. X
  237. X# The main program.
  238. Xcbw: start.o $(cbreq) 
  239. X    cc $(CFLAGS) start.o $(cbreq) \
  240. X    -lcurses -ltermcap -lm -o cbw
  241. X
  242. X# Program to decrypt files after they have been broken by CBW.
  243. Xzeecode: zeecode.o
  244. X    cc $(CFLAGS) zeecode.o -o zeecode
  245. X
  246. X# Program to encrypt files, this is identical to the
  247. X# Unix crypt function based on a two rotor enigma.
  248. Xenigma: enigma.o
  249. X    cc $(CFLAGS) enigma.o -o enigma
  250. X
  251. X#
  252. X# The remaining files are test drivers.
  253. X#
  254. X
  255. Xbd: bdriver.o $(cbreq)
  256. X    cc -g bdriver.o $(cbreq) -lm \
  257. X    -lcurses -ltermcap -lm -o bd
  258. X
  259. Xsd: sdriver.o $(cbreq)
  260. X    cc -g sdriver.o $(cbreq) \
  261. X    -lcurses -ltermcap -lm -o sd
  262. X
  263. Xapprox: approx.o
  264. X    cc -g approx.o -lm -o approx
  265. X
  266. Xstats: stats.o char-io.o
  267. X    cc -g stats.o char-io.o -lm -o stats
  268. X
  269. Xtri: tdriver.o $(cbreq)
  270. X    cc -g tdriver.o $(cbreq) -lm \
  271. X    -lcurses -ltermcap -lm -o tri
  272. X
  273. Xectreq = edriver.o eclass.o cipher.o char-io.o \
  274. X        triglist.o \
  275. X        webster.o user.o gblock.o dblock.o dbsaux.o banner.o \
  276. X        cblocks.o trigram.o stats.o parser.o knit.o \
  277. X        pgate.o perm.o \
  278. X        keylib.o windowlib.o dline.o screen.o 
  279. X
  280. X
  281. Xect: $(ectreq)
  282. X    cc -g $(ectreq) -lm \
  283. X    -o ect
  284. X
  285. Xptt: char-io.o probtab.o
  286. X    cc -g char-io.o probtab.o -lm -o ptt
  287. X
  288. Xdt: disptest.o keylib.o windowlib.o screen.o
  289. X    cc disptest.o keylib.o windowlib.o screen.o -o dt
  290. X
  291. Xtriplace: triplace.o
  292. X
  293. X
  294. END_OF_Makefile
  295. if test 1573 -ne `wc -c <Makefile`; then
  296.     echo shar: \"Makefile\" unpacked with wrong size!
  297. fi
  298. # end of overwriting check
  299. fi
  300. if test -f TODO.txt -a "${1}" != "-c" ; then 
  301.   echo shar: Will not over-write existing file \"TODO.txt\"
  302. else
  303. echo shar: Extracting \"TODO.txt\" \(2021 characters\)
  304. sed "s/^X//" >TODO.txt <<'END_OF_TODO.txt'
  305. XSuggested Improvements to CBW
  306. X
  307. X    See cbw.log for things that have been done.
  308. X
  309. X- Most terminals can be in both inverse video and graphics mode, but
  310. X  the graphics variable format cannot reflect this.
  311. X  - need new mode 'B' meaning both.
  312. X
  313. X- Program doesn't handle blocks less than 256 chars, which
  314. X  makes it hard to decode very short messages.  -- Hard to fix.
  315. X
  316. X- Add window done proc that can cleanup state before
  317. X  a window is replaced.  This would fix the bug in the
  318. X  knitting window which causes it to accept the currently
  319. X  displayed guess.
  320. X
  321. X- Add a decode block command.
  322. X- Make the help window two line tall.
  323. X- Add a command that allows guess words from the keyboard
  324. X  rather than a file.  -- NO better to build vocabulary files.
  325. X
  326. X- Make the propagate command take a range of destination
  327. X  blocks.  E.G. "propagate block 0 to blocks 1 thru 5".
  328. X
  329. X- Make C-U multiply cursor motion commands as in emacs.
  330. X- The command "q<retrun>" should expand into a quit, instead
  331. X  of typing "q<space><return>".
  332. X
  333. X- Add batch mode that applies a sequence of command to all
  334. X  the blocks in a file.
  335. X  -- The driver routines do this, so it should be easy.
  336. X
  337. X- Document the statistics file format.
  338. X- Write a C program for gathering statistics
  339. X  -- The original was written in CLU.
  340. X
  341. X- Add a confirm request to the load command.
  342. X
  343. X- Add a better indicator that the program is busy
  344. X  - especially for the knit command.
  345. X
  346. X- Need better explaination on knitting.
  347. X
  348. X- Add an automatic C-T mode to help verify correct characters.
  349. X- Add command to identify weak characters in the block
  350. X  - i.e., chars that don't deduce anything else.
  351. X
  352. X- Add a save command with a default name that the user can change.
  353. X  - It should default to the load file name.
  354. X
  355. X- If 127 out of 128 wires are known, set the 128th.
  356. X
  357. X- Document the zeecode program.
  358. X
  359. X- Add a command to goto a specific block number.
  360. X- Need better explaination of the pword command.
  361. X
  362. X- Add command that search a dictionary for a word that will
  363. X  fit at a given place.
  364. X  - Worry about case and endings.
  365. END_OF_TODO.txt
  366. if test 2021 -ne `wc -c <TODO.txt`; then
  367.     echo shar: \"TODO.txt\" unpacked with wrong size!
  368. fi
  369. # end of overwriting check
  370. fi
  371. if test -f UU.graphics -a "${1}" != "-c" ; then 
  372.   echo shar: Will not over-write existing file \"UU.graphics\"
  373. else
  374. echo shar: Extracting \"UU.graphics\" \(327 characters\)
  375. sed "s/^X//" >UU.graphics <<'END_OF_UU.graphics'
  376. Xbegin 644 graphics
  377. XM&T9A8F-D969G:!M'"AM&:6IK;&UN;W`;1PH;1G%R<W1U=G=X&T<*&T9Y>GM\
  378. XM?7X;1PH;1D%"0T1%1D=(&T<*&T9)2DM,34Y/4!M'"AM&45)35%565U@;1PH;
  379. XM1EE:6UQ=(%\;1PHM+2T*&T8!`@,$!08'"!M'"AM&"0H+#`T.#Q`;1PH;1A$2
  380. XM$Q05%A<8&T<*&T89&B`<'1\;1PHM+2T*&T8Q,C,T-38W.#DP&T<*&T8A0",D
  381. XF)5XF*B@I&T<*&T8@+5\]*V!^6UU<?#LZ)R)[?2P\+CXO/QM'"@H*
  382. X`
  383. Xend
  384. END_OF_UU.graphics
  385. if test 327 -ne `wc -c <UU.graphics`; then
  386.     echo shar: \"UU.graphics\" unpacked with wrong size!
  387. fi
  388. # end of overwriting check
  389. fi
  390. if test -f approx.c -a "${1}" != "-c" ; then 
  391.   echo shar: Will not over-write existing file \"approx.c\"
  392. else
  393. echo shar: Extracting \"approx.c\" \(1891 characters\)
  394. sed "s/^X//" >approx.c <<'END_OF_approx.c'
  395. X/*
  396. X * Fast approximations of useful math functions.
  397. X *
  398. X * Robert W. Baldwin, May 1985.
  399. X */
  400. X
  401. X
  402. X#include    <stdio.h>
  403. X#include    <math.h>
  404. X#include    "window.h"
  405. X#include    "specs.h"
  406. X
  407. X
  408. X#define STANDALONE    FALSE
  409. X
  410. X#define    NFEXP        100        /* Number of entries in fexp_value table. */
  411. X#define    DXFEXP        0.05    /* Interval width in fexp table. */
  412. X#define    MAXFEXP        (NFEXP * DXFEXP)    /* Max value < this */
  413. X
  414. X
  415. X/* Table of values for exp(-(x*x)/2) starting with zero at intervals of 0.1
  416. X * The values of the derivative of exp(-(x*x)/2) are in fexp_deriv.
  417. X */
  418. Xfloat    fexp_value[NFEXP];
  419. Xfloat    fexp_deriv[NFEXP];
  420. X
  421. X
  422. X/* Table for fast square root computation.
  423. X */
  424. Xfloat    isqrt[BLOCKSIZE];
  425. X
  426. X
  427. X#if STANDALONE
  428. Xmain()
  429. X{
  430. X    int        i;
  431. X    float    fi;
  432. X
  433. X    printf("\t\t\t\tTable of exp(-(x*x)/2)");
  434. X    printf("\nX\t\treal\t\tapprox");
  435. X    printf("\n\n");
  436. X
  437. X    approx_init();
  438. X
  439. X    for (i = 0 ; i < (NFEXP + 5) ; i++)  {
  440. X        fi = i;
  441. X        fi = fi * DXFEXP;
  442. X        fi += DXFEXP/2.0;
  443. X        printf("%f\t", fi);
  444. X        printf("%f\t", exp(-(fi*fi)/2));
  445. X        printf("%f", fexp(fi));
  446. X        printf("\n");
  447. X        }
  448. X}
  449. X#endif
  450. X
  451. X
  452. X
  453. X/* Initialize the approximation tables.
  454. X */
  455. Xapprox_init()
  456. X{
  457. X    sqrt_tab();
  458. X    fexp_tab();
  459. X}
  460. X
  461. X
  462. X/* Fill in the table of square roots.
  463. X */
  464. Xsqrt_tab()
  465. X{
  466. X    reg    int        i;
  467. X        float    fi;
  468. X
  469. X    for (i = 0 ; i < BLOCKSIZE ; i++)  {
  470. X        fi = i;
  471. X        isqrt[i] = sqrt(fi);
  472. X        }
  473. X}
  474. X
  475. X
  476. X/* Fill in th approximation table for fexp.
  477. X */
  478. Xfexp_tab()
  479. X{
  480. X    int        i;
  481. X    float    fi;
  482. X    float    value;
  483. X    float    deriv;
  484. X
  485. X    for (i = 0 ; i < NFEXP ; i++)  {
  486. X        fi = i;
  487. X        fi = fi * DXFEXP;
  488. X        value = exp(-(fi*fi)/2);
  489. X        deriv = -fi * value;
  490. X        fexp_value[i] = value;
  491. X        fexp_deriv[i] = deriv;
  492. X        }
  493. X}
  494. X
  495. X
  496. X/* Return a fast approximation to exp(-(x*x)/2).
  497. X */
  498. Xfloat    fexp(x)
  499. Xreg    float    x;
  500. X{
  501. Xreg    int        index;
  502. X    float    approx;
  503. Xreg    float    result;
  504. X
  505. X    x = abs(x);
  506. X    if (x >= MAXFEXP)
  507. X        return(0.0);
  508. X    index = x * (1.0 / DXFEXP);
  509. X    approx = index;
  510. X    approx = approx * DXFEXP;
  511. X    result = fexp_value[index];
  512. X    result += (x - approx) * fexp_deriv[index];
  513. X
  514. X    return(result);
  515. X}
  516. END_OF_approx.c
  517. if test 1891 -ne `wc -c <approx.c`; then
  518.     echo shar: \"approx.c\" unpacked with wrong size!
  519. fi
  520. # end of overwriting check
  521. fi
  522. if test -f autotri.h -a "${1}" != "-c" ; then 
  523.   echo shar: Will not over-write existing file \"autotri.h\"
  524. else
  525. echo shar: Extracting \"autotri.h\" \(1158 characters\)
  526. sed "s/^X//" >autotri.h <<'END_OF_autotri.h'
  527. X/*
  528. X * Definitions for automatically guessing with trigrams. 
  529. X */
  530. X
  531. X
  532. X#define    PERMSZ        20
  533. X#define    TRIGTABSZ    150
  534. X#define    TRIGBUFSZ    (4*(TRIGTABSZ+1))
  535. X
  536. X
  537. X
  538. X#define    trig_ent    struct xtrigent
  539. Xtrig_ent    {
  540. X        float    prob;        /* A priori probability of this trigram. */
  541. X        char    *trigram;    /* Null for last entry in table. */
  542. X        int        notused;    /* For compatibility with pqueue. */
  543. X        };
  544. X
  545. X
  546. X#define    atrinfo    struct xatrinfo
  547. Xatrinfo    {
  548. X        ecinfo        *eci;
  549. X        /* A guess must have a better score than this field. */
  550. X        float        max_score;
  551. X        /* A guess must deduce atleast this many chars. */
  552. X        int            min_total_chars;
  553. X        /* Each wire of the guess must deduce this many chars. */
  554. X        int            min_wire_chars;
  555. X        char        *best_trigram;
  556. X        float        best_score;
  557. X        int            gcount;            /* Total number of guesses. */
  558. X        float        total_score;    /* Their cummulative score. */
  559. X        /* NONE terminated string of the chars deduced by the best trigram. */
  560. X        /* Does not include the trigram itself. */
  561. X        int            best_pvec[BLOCKSIZE+1];
  562. X        /* Table of permutation wirings deduced by the best guess so far. */
  563. X        /* The table is terminated by a perment with x == NONE. */
  564. X        perment        best_permvec[PERMSZ];
  565. X        };
  566. X
  567. X
  568. Xextern    trig_ent    trig_tab[];
  569. X
  570. END_OF_autotri.h
  571. if test 1158 -ne `wc -c <autotri.h`; then
  572.     echo shar: \"autotri.h\" unpacked with wrong size!
  573. fi
  574. # end of overwriting check
  575. fi
  576. if test -f banner.c -a "${1}" != "-c" ; then 
  577.   echo shar: Will not over-write existing file \"banner.c\"
  578. else
  579. echo shar: Extracting \"banner.c\" \(1477 characters\)
  580. sed "s/^X//" >banner.c <<'END_OF_banner.c'
  581. X/*
  582. X * Banner window abstraction.  Just a title text with default behavior.
  583. X *
  584. X * Robert W. Baldwin,  December 1984.
  585. X */
  586. X
  587. X
  588. X#include    <stdio.h>
  589. X#include    "window.h"
  590. X#include    "layout.h"
  591. X
  592. X
  593. X/* Window for the title banner. */
  594. X
  595. Xdispline    banline1 = {
  596. X            1,1,            /* Origin. */
  597. X            1,MAXWIDTH,        /* Height and width. */
  598. X            1,1,            /* Initial cursor position */
  599. X            NULL,            /* No private data. */
  600. X            wl_setcur,        /* Firstime = Set cursor to current value. */
  601. X            wl_noop,        /* Lasttime = do nothing. */
  602. X            wl_dldraw,        /* Default dispaly line draw routine. */
  603. X            dokey,            /* Default keystroke handler. */
  604. X            arwktab,        /* Basic arrow keystroke handler. */
  605. X            1,MAXWIDTH,        /* Min and Max column for cursor in line. */
  606. X            };
  607. X
  608. Xdispline    *banlines[] = {
  609. X            &banline1,        /* List of display lines for the banner. */
  610. X            NULL,
  611. X            };
  612. X
  613. Xtwindow        banner = {
  614. X            1,1,            /* Origin. */
  615. X            1,MAXWIDTH,        /* Height and width. */
  616. X            1,1,            /* Initial cursor position */
  617. X            NULL,            /* No private data. */
  618. X            wl_setcur,        /* Firstime = accept current cursor position. */
  619. X            wl_noop,        /* Lasttime = do nothing. */
  620. X            wl_twdraw,        /* Simple draw routine. */
  621. X            dokey,            /* Default keystroke handler. */
  622. X            arwktab,        /* Basic arrow keystroke handler. */
  623. X            banlines,
  624. X            };
  625. X
  626. X
  627. X
  628. X/* Initialize the banner window and return a pointer to it.
  629. X * Fill in the banner text.
  630. X */
  631. Xgwindow *(ibanner())
  632. X{
  633. X    displine    *line;
  634. X    int            i;
  635. X
  636. X    line = banner.dlines[0];
  637. X    clrdline(line);
  638. X    setndline(line, BANTEXT, BANLM);
  639. X    return ((gwindow *) &banner);
  640. X}
  641. END_OF_banner.c
  642. if test 1477 -ne `wc -c <banner.c`; then
  643.     echo shar: \"banner.c\" unpacked with wrong size!
  644. fi
  645. # end of overwriting check
  646. fi
  647. if test -f cblocks.c -a "${1}" != "-c" ; then 
  648.   echo shar: Will not over-write existing file \"cblocks.c\"
  649. else
  650. echo shar: Extracting \"cblocks.c\" \(1196 characters\)
  651. sed "s/^X//" >cblocks.c <<'END_OF_cblocks.c'
  652. X/*
  653. X * Abstraction for the table of cipher text blocks.
  654. X *
  655. X * Robert W. Baldwin, December 1984.
  656. X *
  657. X * History:
  658. X * 3/8/85    Bob Baldwin        Changed fname to cipherfile.
  659. X * 1/13/85  Bob Baldwin        Permutation stuff moved to perm.c
  660. X */
  661. X
  662. X
  663. X#include    <stdio.h>
  664. X#include    "window.h"
  665. X#include    "layout.h"
  666. X#include    "specs.h"
  667. X
  668. X
  669. X
  670. X#define    FROMSTART    0        /* For fseek call, how offset measured. */
  671. X
  672. X
  673. X/* Input file name for ciphertext, set by main. */
  674. Xchar    *cipherfile;
  675. X
  676. X
  677. X/* Fill the given buffer with the i-th ciphertext block.
  678. X * The block index is zero-based.
  679. X * Return FALSE if try to read non-existant bytes.
  680. X */
  681. Xint    fillcbuf(blocknum, cbuf)
  682. Xint        blocknum;
  683. Xchar    *cbuf;
  684. X{
  685. X    FILE    *fd;
  686. X    long    offset;
  687. X    long    res;
  688. X    int        i;
  689. X
  690. X    if ((blocknum < 0) || (NPERMS <= blocknum))  return(FALSE);
  691. X
  692. X    if ((fd = fopen(cipherfile, "r")) == NULL)  {
  693. X        printf("\nCould not open %s to read ciphertext.\n", cipherfile);
  694. X        exit(0);
  695. X        }
  696. X
  697. X    offset = blocknum * BLOCKSIZE;
  698. X    fseek(fd, offset, FROMSTART);
  699. X    res = ftell(fd);
  700. X    if (res != offset) {
  701. X        printf("\nSeek failed on %s to %d, got %d.\n", cipherfile, offset,res);
  702. X        exit(0);
  703. X        }
  704. X
  705. X    if (fread(cbuf,sizeof(*(cbuf)),BLOCKSIZE,fd) != BLOCKSIZE)  {
  706. X        return(FALSE);
  707. X        }
  708. X
  709. X    fclose(fd);
  710. X
  711. X    return(TRUE);
  712. X}
  713. END_OF_cblocks.c
  714. if test 1196 -ne `wc -c <cblocks.c`; then
  715.     echo shar: \"cblocks.c\" unpacked with wrong size!
  716. fi
  717. # end of overwriting check
  718. fi
  719. if test -f char-io.c -a "${1}" != "-c" ; then 
  720.   echo shar: Will not over-write existing file \"char-io.c\"
  721. else
  722. echo shar: Extracting \"char-io.c\" \(1265 characters\)
  723. sed "s/^X//" >char-io.c <<'END_OF_char-io.c'
  724. X/*
  725. X * Read and write slashified characters.
  726. X * Translated from Tim Shepard's CLU code. 
  727. X */
  728. X
  729. X#include    <stdio.h>
  730. X
  731. X#define    EOL    (-37)
  732. X
  733. Xwrite_char(out, c)
  734. XFILE    *out;
  735. Xint        c;
  736. X{
  737. X   char    *s;
  738. X   char    buf[6];
  739. X
  740. X   if (c == '\\')
  741. X      {s = "\\\\";}
  742. X   else if (c == '\n')
  743. X      {s = "\\n";}
  744. X   else if (c == '\t')
  745. X      {s = "\\t";}
  746. X   else if (c == '\f')
  747. X      {s = "\\p";}
  748. X   else if (c == '\b')
  749. X      {s = "\\b";}
  750. X   else if (c == '\r')
  751. X      {s = "\\r";}
  752. X   else if (c < ' ' || '~' < c)  {
  753. X      s = buf;
  754. X      s[0] = '\\';
  755. X      s[1] = '0' + (c/64);
  756. X      s[2] = '0' + ((c%64)/8);
  757. X      s[3] = '0' + (c%8);
  758. X      s[4] = '\000';
  759. X      }
  760. X   else  {
  761. X      s = buf;
  762. X      s[0] = c;
  763. X      s[1] = '\000';
  764. X      }
  765. X
  766. X   fprintf(out, "%s", s);
  767. X}
  768. X
  769. X
  770. Xint    read_char(inp)
  771. XFILE    *inp;
  772. X{
  773. X   int    c;
  774. X
  775. X   c = getc(inp);
  776. X   if (c == EOF) return(EOF);
  777. X   if (c == '\n') return(EOL);
  778. X   if (c == '\\')  {
  779. X      c = getc(inp);
  780. X      if (c == EOF) return(EOF);
  781. X      if (c == 'n')
  782. X         {c = '\n';}
  783. X      else if (c == 't')
  784. X         {c = '\t';}
  785. X      else if (c == 'p')
  786. X         {c = '\f';}
  787. X      else if (c == 'b')
  788. X         {c = '\b';}
  789. X      else if (c == 'r')
  790. X         {c = '\r';}
  791. X      else if ('0' <= c  &&  c <= '7')  {
  792. X         c = 64*(c - '0');
  793. X         c = c + 8*(getc(inp)-'0');
  794. X         c = c + 1*(getc(inp)-'0');
  795. X         }
  796. X   }
  797. X   return(c);
  798. X}
  799. END_OF_char-io.c
  800. if test 1265 -ne `wc -c <char-io.c`; then
  801.     echo shar: \"char-io.c\" unpacked with wrong size!
  802. fi
  803. # end of overwriting check
  804. fi
  805. if test -f common.words -a "${1}" != "-c" ; then 
  806.   echo shar: Will not over-write existing file \"common.words\"
  807. else
  808. echo shar: Extracting \"common.words\" \(259 characters\)
  809. sed "s/^X//" >common.words <<'END_OF_common.words'
  810. X the 
  811. X The 
  812. X\nThe 
  813. X.  The 
  814. X with 
  815. X that 
  816. X then 
  817. X when 
  818. X than 
  819. X when 
  820. X\nWhen 
  821. X When 
  822. X\nWhat 
  823. X What 
  824. X what 
  825. X from 
  826. X\nFor 
  827. X.  For
  828. X for 
  829. X but 
  830. X and 
  831. X not 
  832. X are 
  833. X may 
  834. X will 
  835. X have 
  836. X has 
  837. X been 
  838. X each 
  839. X only 
  840. X also 
  841. X more 
  842. X both 
  843. X one 
  844. X two 
  845. Xwould 
  846. Xcould 
  847. Xshould 
  848. END_OF_common.words
  849. if test 259 -ne `wc -c <common.words`; then
  850.     echo shar: \"common.words\" unpacked with wrong size!
  851. fi
  852. # end of overwriting check
  853. fi
  854. if test -f dblock.h -a "${1}" != "-c" ; then 
  855.   echo shar: Will not over-write existing file \"dblock.h\"
  856. else
  857. echo shar: Extracting \"dblock.h\" \(667 characters\)
  858. sed "s/^X//" >dblock.h <<'END_OF_dblock.h'
  859. Xextern    int    dbsrc2pos();
  860. Xextern    int    dbsp2row();
  861. Xextern    int    dbsp2col();
  862. Xextern    int    dbsdpchar();
  863. X
  864. X
  865. X
  866. X#define dbsinfo    struct xdbsinfo
  867. Xstruct    xdbsinfo    {
  868. X        char    *cbuf;        /* Ciphertext block. */
  869. X        int        *pbuf;        /* Plaintext block. */
  870. X        int        *perm;        /* Partial permutation, -1 -> none known. */
  871. X        char    *mbuf;        /* Bools for which chars are marked. */
  872. X        int        wirecnt;    /* Number of known wires in perm. */
  873. X        int        cmdloc;        /* Position in pbuf where cmd started. */
  874. X        int        cmdnext;    /* Index for next char to add to cmdbuf. */
  875. X        int        *cmdbuf;    /* Command from user. */
  876. X        int        *operm;        /* Permutation after last command. */
  877. X        int        blknum;        /* Zero based index of current block. */
  878. X        };
  879. END_OF_dblock.h
  880. if test 667 -ne `wc -c <dblock.h`; then
  881.     echo shar: \"dblock.h\" unpacked with wrong size!
  882. fi
  883. # end of overwriting check
  884. fi
  885. if test -f dbsaux.c -a "${1}" != "-c" ; then 
  886.   echo shar: Will not over-write existing file \"dbsaux.c\"
  887. else
  888. echo shar: Extracting \"dbsaux.c\" \(2998 characters\)
  889. sed "s/^X//" >dbsaux.c <<'END_OF_dbsaux.c'
  890. X/*
  891. X * dblock.c takes too long to compile, so this is separate.
  892. X *
  893. X * Robert W. Baldwin, December 1984.
  894. X */
  895. X
  896. X
  897. X#include    <stdio.h>
  898. X#include    "window.h"
  899. X#include    "layout.h"
  900. X#include    "specs.h"
  901. X#include    "pqueue.h"
  902. X#include    "cipher.h"
  903. X
  904. X#include    "dblock.h"
  905. X
  906. X
  907. Xecinfo    t_ecinfo;
  908. X
  909. X
  910. X/* Try all the possible characters at the current position.
  911. X * Display those that do not generate any conflicts.
  912. X */
  913. Xdbstryall(dbs, k)
  914. Xgwindow    *dbs;
  915. Xkey        k;
  916. X{
  917. X    int        col, pos;
  918. X    int        oldrow, oldcol;
  919. X    int        i;
  920. X    int        tchar;
  921. X    ecinfo    *ecbi;
  922. X    dbsinfo    *dbsi;
  923. X    int        pque_index;
  924. X    pqueue_hdr    pque_hdr;
  925. X    pqueue_ent    the_pque[MAXCHAR+1];
  926. X
  927. X    dbsi = ((dbsinfo *) dbs->wprivate);
  928. X    ecbi = &t_ecinfo;
  929. X
  930. X    pque_init(&pque_hdr, 1000.0, &the_pque[0], MAXCHAR+1);
  931. X    ec_init(dbsi->cbuf, dbsi->perm, ecbi);
  932. X    
  933. X    oldrow = dbs->wcur_row;
  934. X    oldcol = dbs->wcur_col;
  935. X    pos = dbsrc2pos(oldrow, oldcol);
  936. X    dbstrypq(ecbi, &pque_hdr, pos);
  937. X
  938. X    wl_setcur(dbs, dbsp2row(BLOCKSIZE), dbsp2col(BLOCKSIZE));
  939. X
  940. X    tchar = 0;
  941. X    for (col = 1 ; col < dbs->wwidth ; col++)  {
  942. X        pque_index = col - 1;
  943. X        if (pque_index >= pque_hdr.next_index)  break;
  944. X        tchar = the_pque[pque_index].value1;
  945. X        plnchars(1, char2sym(tchar));
  946. X        }
  947. X  alldone:
  948. X    plnchars((dbs->wwidth) - col, ' ');
  949. X    wl_setcur(dbs, oldrow, oldcol);
  950. X}
  951. X
  952. X
  953. X/* Try all chars in position pos.  Added them to a priority queue.
  954. X * The most likely character appears first.
  955. X */
  956. Xdbstrypq(ecbi, pque_hdr, pos)
  957. Xecinfo        *ecbi;
  958. Xpqueue_hdr    *pque_hdr;
  959. Xint            pos;
  960. X{
  961. X    int        plainchar;
  962. X    int        added;
  963. X    float    score;
  964. X    extern    float    score2_scale, score1_scale;
  965. X    float    score1, score2;
  966. X    float    sdev1, sdev2;        /* Standard Deviation for 1st and 2nd stats. */
  967. X    gsinfo    tmpgsi;
  968. X    gsinfo    *gsi;
  969. X    int        gssbuf[BLOCKSIZE+1];
  970. X
  971. X    gsi    = &tmpgsi;
  972. X    gsi_init(gsi, ecbi->plaintext, gssbuf);
  973. X
  974. X    for (plainchar = 0 ; plainchar <= MAXCHAR ; plainchar++)  {
  975. X        gsi_clear(gsi);
  976. X        added = gsi_class_guess(gsi, ecbi, pos, plainchar);
  977. X        if (added > 0) {
  978. X            sdev1 = gsi_1score(gsi);
  979. X            if (sdev1 < 0.0)
  980. X                continue;
  981. X            sdev2 = gsi_2score(gsi);
  982. X            if (sdev2 < 0.0)
  983. X                continue;
  984. X            score = sdev1 + sdev2;
  985. X            pque_add(pque_hdr, score, plainchar, 0);
  986. X            }
  987. X        }
  988. X}
  989. X
  990. X
  991. X/* Word search from dictionary.  Try to find the word at the cursor position.
  992. X * The cursor must be at either the beginning or end of a word as indicated
  993. X * by the cursor being adjacent to a whitespace character.
  994. X * 
  995. X * For now, a pattern is extracted an a word lookup command gets executed.
  996. X * The keystroke argument, k, is not used.
  997. X */
  998. Xdbswrdsrch(dbs, k)
  999. Xgwindow    *dbs;
  1000. Xkey        k;
  1001. X{
  1002. X    int    oldrow, oldcol;        /* To reset cursor pos if needed. */
  1003. X    int    pos;            /* Char offset in block. */
  1004. X    int    prev_char;
  1005. X    ecinfo    *ecbi;
  1006. X    dbsinfo    *dbsi;
  1007. X    
  1008. X    dbsi = ((dbsinfo *) dbs->wprivate);
  1009. X    ecbi = &t_ecinfo;
  1010. X    ec_init(dbsi->cbuf, dbsi->perm, ecbi);
  1011. X    
  1012. X    oldrow = dbs->wcur_row;
  1013. X    oldcol = dbs->wcur_col;
  1014. X    pos = dbsrc2pos(oldrow, oldcol);
  1015. X    prev_char = pos > 0 ? dbsi->pbuf[pos-1] : NONE;
  1016. X    if (isletter(prev_char)) {
  1017. X        usrstatus(&user,
  1018. X           "Word Search: Cursor must be start of a word.");
  1019. X        return;
  1020. X        }
  1021. X
  1022. X/*    websearch(&webster, ecbi, pos, TRUE); */
  1023. X    return;
  1024. X}
  1025. END_OF_dbsaux.c
  1026. if test 2998 -ne `wc -c <dbsaux.c`; then
  1027.     echo shar: \"dbsaux.c\" unpacked with wrong size!
  1028. fi
  1029. # end of overwriting check
  1030. fi
  1031. if test -f enigma.c -a "${1}" != "-c" ; then 
  1032.   echo shar: Will not over-write existing file \"enigma.c\"
  1033. else
  1034. echo shar: Extracting \"enigma.c\" \(2225 characters\)
  1035. sed "s/^X//" >enigma.c <<'END_OF_enigma.c'
  1036. Xstatic char *sccsid = "@(#)crypt.c    4.2 (Berkeley) 7/9/81";
  1037. X
  1038. X/*
  1039. X *    A one-rotor machine designed along the lines of Enigma
  1040. X *    but considerably trivialized.
  1041. X */
  1042. X
  1043. X#define ECHO 010
  1044. X#include <stdio.h>
  1045. X#define ROTORSZ 256
  1046. X#define MASK 0377
  1047. Xchar    t1[ROTORSZ];
  1048. Xchar    t2[ROTORSZ];
  1049. Xchar    t3[ROTORSZ];
  1050. Xchar    deck[ROTORSZ];
  1051. Xchar    *getpass();
  1052. Xchar    buf[13];
  1053. X
  1054. Xsetup(pw)
  1055. Xchar *pw;
  1056. X{
  1057. X    int ic, i, k, temp, pf[2];
  1058. X    unsigned random;
  1059. X    long seed;
  1060. X
  1061. X    strncpy(buf, pw, 8);
  1062. X    while (*pw)
  1063. X        *pw++ = '\0';
  1064. X    buf[8] = buf[0];
  1065. X    buf[9] = buf[1];
  1066. X    pipe(pf);
  1067. X    if (fork()==0) {
  1068. X        close(0);
  1069. X        close(1);
  1070. X        dup(pf[0]);
  1071. X        dup(pf[1]);
  1072. X        execl("/usr/lib/makekey", "-", 0);
  1073. X        execl("/lib/makekey", "-", 0);
  1074. X        exit(1);
  1075. X    }
  1076. X    write(pf[1], buf, 10);
  1077. X    wait((int *)NULL);
  1078. X    if (read(pf[0], buf, 13) != 13) {
  1079. X        fprintf(stderr, "crypt: cannot generate key\n");
  1080. X        exit(1);
  1081. X    }
  1082. X    seed = 123;
  1083. X    for (i=0; i<13; i++)
  1084. X        seed = seed*buf[i] + i;
  1085. X    for(i=0;i<ROTORSZ;i++) {
  1086. X        t1[i] = i;
  1087. X        deck[i] = i;
  1088. X    }
  1089. X    for(i=0;i<ROTORSZ;i++) {
  1090. X        seed = 5*seed + buf[i%13];
  1091. X        random = seed % 65521;
  1092. X        k = ROTORSZ-1 - i;
  1093. X        ic = (random&MASK)%(k+1);
  1094. X        random >>= 8;
  1095. X        temp = t1[k];
  1096. X        t1[k] = t1[ic];
  1097. X        t1[ic] = temp;
  1098. X        if(t3[k]!=0) continue;
  1099. X        ic = (random&MASK) % k;
  1100. X        while(t3[ic]!=0) ic = (ic+1) % k;
  1101. X        t3[k] = ic;
  1102. X        t3[ic] = k;
  1103. X    }
  1104. X    for(i=0;i<ROTORSZ;i++)
  1105. X        t2[t1[i]&MASK] = i;
  1106. X}
  1107. X
  1108. Xmain(argc, argv)
  1109. Xchar *argv[];
  1110. X{
  1111. X    register i, n1, n2, nr1, nr2;
  1112. X    int secureflg = 0;
  1113. X
  1114. X    if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 's') {
  1115. X        argc--;
  1116. X        argv++;
  1117. X        secureflg = 1;
  1118. X    }
  1119. X    if (argc != 2){
  1120. X        setup(getpass("Enter key:"));
  1121. X    }
  1122. X    else
  1123. X        setup(argv[1]);
  1124. X    n1 = 0;
  1125. X    n2 = 0;
  1126. X    nr2 = 0;
  1127. X
  1128. X    while((i=getchar()) >=0) {
  1129. X        if (secureflg) {
  1130. X            nr1 = deck[n1]&MASK;
  1131. X            nr2 = deck[nr1]&MASK;
  1132. X        } else {
  1133. X            nr1 = n1;
  1134. X        }
  1135. X        i = t2[(t3[(t1[(i+nr1)&MASK]+nr2)&MASK]-nr2)&MASK]-nr1;
  1136. X        putchar(i);
  1137. X        n1++;
  1138. X        if(n1==ROTORSZ) {
  1139. X            n1 = 0;
  1140. X            n2++;
  1141. X            if(n2==ROTORSZ) n2 = 0;
  1142. X            if (secureflg) {
  1143. X                shuffle(deck);
  1144. X            } else {
  1145. X                nr2 = n2;
  1146. X            }
  1147. X        }
  1148. X    }
  1149. X}
  1150. X
  1151. Xshuffle(deck)
  1152. X    char deck[];
  1153. X{
  1154. X    int i, ic, k, temp;
  1155. X    unsigned random;
  1156. X    static long seed = 123;
  1157. X
  1158. X    for(i=0;i<ROTORSZ;i++) {
  1159. X        seed = 5*seed + buf[i%13];
  1160. X        random = seed % 65521;
  1161. X        k = ROTORSZ-1 - i;
  1162. X        ic = (random&MASK)%(k+1);
  1163. X        temp = deck[k];
  1164. X        deck[k] = deck[ic];
  1165. X        deck[ic] = temp;
  1166. X    }
  1167. X}
  1168. END_OF_enigma.c
  1169. if test 2225 -ne `wc -c <enigma.c`; then
  1170.     echo shar: \"enigma.c\" unpacked with wrong size!
  1171. fi
  1172. # end of overwriting check
  1173. fi
  1174. if test -f h19.slice -a "${1}" != "-c" ; then 
  1175.   echo shar: Will not over-write existing file \"h19.slice\"
  1176. else
  1177. echo shar: Extracting \"h19.slice\" \(1164 characters\)
  1178. sed "s/^X//" >h19.slice <<'END_OF_h19.slice'
  1179. X# For GRAPHICSMAP, the first char must be one of the following:
  1180. X# \G - graphics mode
  1181. X# \N - normal mode
  1182. X# \S - standout (inverse) mode
  1183. X# The remaining positions use the regular slash codes.
  1184. X#
  1185. Xsetenv GRAPHICSMAP    'tb=\Gh:lf=\Gk:cr=\Gg:na=\Gi:\
  1186. X            ff=\G~:cc=\Gw:uk=\G^:ul=\Gz:\
  1187. X            vb=\G'\`':hb=\Ga:ll=\Ge'
  1188. X
  1189. X# For KEYMAP, the symbol \E is the same as \033 (escape), it can
  1190. X# appear anywhere in the value fields.
  1191. X# Info in KEYMAP superceeds info in the TERMCAP file/variable.
  1192. X#
  1193. X#setenv KEYMAP \
  1194. X#'pr=\ES:ne=\033T:ac=\033U:jc=\033V:up=\EA:do=\EB:ri=\EC:le=\ED:'
  1195. X
  1196. X
  1197. X# Here is a full termcap entry for the heath.
  1198. X# The original was missing ks and ke.
  1199. X#
  1200. Xsetenv TERMCAP \
  1201. X'kb|h19|heath|h19-b|h19b|heathkit|heath-19|z19|zenith|heathkit h19:\
  1202. X    :cr=^M:nl=^J:bl=^G:\
  1203. X    :al=1*\EL:am:le=^H:bs:cd=\EJ:ce=\EK:cl=\EE:cm=\EY%+ %+ :co#80:dc=\EN:\
  1204. X    :dl=1*\EM:do=\EB:ei=\EO:ho=\EH:im=\E@:li#24:mi:nd=\EC:as=\EF:ae=\EG:\
  1205. X    :ms:ta=^I:pt:sr=\EI:se=\Eq:so=\Ep:up=\EA:vs=\Ex4:ve=\Ey4:\
  1206. X    :kb=^h:ku=\EA:kd=\EB:kl=\ED:kr=\EC:kh=\EH:kn#8:\
  1207. X    :k1=\ES:k2=\ET:k3=\EU:k4=\EV:k5=\EW:\
  1208. X    :l6=blue:l7=red:l8=white:k6=\EP:k7=\EQ:k8=\ER:\
  1209. X    :es:hs:ts=\Ej\Ex5\Ex1\EY8%+ \Eo:fs=\Ek\Ey5:ds=\Ey1:\
  1210. X    :ks=\Et:ke=\Eu'
  1211. END_OF_h19.slice
  1212. if test 1164 -ne `wc -c <h19.slice`; then
  1213.     echo shar: \"h19.slice\" unpacked with wrong size!
  1214. fi
  1215. # end of overwriting check
  1216. fi
  1217. if test -f keylib.c -a "${1}" != "-c" ; then 
  1218.   echo shar: Will not over-write existing file \"keylib.c\"
  1219. else
  1220. echo shar: Extracting \"keylib.c\" \(1944 characters\)
  1221. sed "s/^X//" >keylib.c <<'END_OF_keylib.c'
  1222. X/*
  1223. X * Library of keystroke handling routines.
  1224. X *
  1225. X * Robert W. Baldwin,  December 1984.
  1226. X */
  1227. X
  1228. X#include    <stdio.h>
  1229. X#include    "window.h"
  1230. X#include    "terminal.h"
  1231. X#include    "specs.h"
  1232. X
  1233. X
  1234. X/* Keystroke table for default arrow key functionality.
  1235. X * Used by the windows that don't accept keystroke commands.
  1236. X */
  1237. Xkeyer    arwktab[]    =    {
  1238. X        {CGO_UP, jogup},
  1239. X        {CGO_DOWN, jogdown},
  1240. X        {CGO_LEFT, jogleft},
  1241. X        {CGO_RIGHT, jogright},
  1242. X        {0, NULL},
  1243. X};
  1244. X
  1245. X
  1246. X
  1247. X/* The following routines move the cursor.
  1248. X * If the cursor is still in the window, they update the
  1249. X * cursor location in the window's data structure.
  1250. X */
  1251. Xjogup(w,k)
  1252. Xgwindow    *w;
  1253. Xkey        k;
  1254. X{
  1255. X    if (w->wcur_row > 1) {
  1256. X        w->wcur_row--;
  1257. X        }
  1258. X    jogcursor(1);
  1259. X}
  1260. X
  1261. Xjogdown(w,k)
  1262. Xgwindow    *w;
  1263. Xkey        k;
  1264. X{
  1265. X    if (w->wcur_row < w->wheight) {
  1266. X        w->wcur_row++;
  1267. X        }
  1268. X    jogcursor(2);
  1269. X}
  1270. X
  1271. Xjogleft(w,k)
  1272. Xgwindow    *w;
  1273. Xkey        k;
  1274. X{
  1275. X    if (w->wcur_col > 1) {
  1276. X        w->wcur_col--;
  1277. X        }
  1278. X    jogcursor(3);
  1279. X}
  1280. X
  1281. Xjogright(w,k)
  1282. Xgwindow    *w;
  1283. Xkey        k;
  1284. X{
  1285. X    if (w->wcur_col < w->wwidth) {
  1286. X        w->wcur_col++;
  1287. X        }
  1288. X    jogcursor(4);
  1289. X}
  1290. X
  1291. X
  1292. X
  1293. X/* ddokey is the lookup routine for interpreting keys.
  1294. X * It searches a table of keyer entries for one that matches the
  1295. X * given key.  If a match is found, it calls the corresponding
  1296. X * routine and returns TRUE.  Otherwise returns FALSE.
  1297. X * The end of the table is marked by an entry with a keychar = 0 or -1.
  1298. X * If it is -1, the proc in that entry will be called with the key,
  1299. X * and TRUE is returned.  If it is 0, the no-match status is returned.
  1300. X */
  1301. Xint ddokey(w, k, ktab)
  1302. Xgwindow    *w;        /* Window */
  1303. Xkey    k;        /* Key to handle */
  1304. Xkeyer    *ktab;        /* Table of handling procedures */
  1305. X{
  1306. X    int    cmd;
  1307. X
  1308. X    cmd = (k >> CMDSHIFT) & CMDMASK;
  1309. X    for ( ; ktab->keychar != 0 ; ktab++ )  {
  1310. X        if (ktab->keychar == cmd  ||  ktab->keychar == -1)  {
  1311. X            (*(ktab->keyproc))(w, (k & CHARM));
  1312. X            return(TRUE);
  1313. X            }
  1314. X        }
  1315. X
  1316. X    return(FALSE);
  1317. X}
  1318. X
  1319. X
  1320. X
  1321. X/* Lookup and call a keyproc in the window's key handling table.
  1322. X */
  1323. Xdokey(w, k)
  1324. Xgwindow        *w;
  1325. Xkey            k;
  1326. X{
  1327. X    return(ddokey(w, k, w->wkeyprocs));
  1328. X}
  1329. END_OF_keylib.c
  1330. if test 1944 -ne `wc -c <keylib.c`; then
  1331.     echo shar: \"keylib.c\" unpacked with wrong size!
  1332. fi
  1333. # end of overwriting check
  1334. fi
  1335. if test -f layout.h -a "${1}" != "-c" ; then 
  1336.   echo shar: Will not over-write existing file \"layout.h\"
  1337. else
  1338. echo shar: Extracting \"layout.h\" \(1450 characters\)
  1339. sed "s/^X//" >layout.h <<'END_OF_layout.h'
  1340. X/*
  1341. X * Constants that define the layout of the screen.
  1342. X *
  1343. X * Robert W. Baldwin, December 1984.
  1344. X */
  1345. X
  1346. X
  1347. X
  1348. X/* Parameter for the screen layout. */
  1349. X
  1350. X#define    WINDNUM        7                /* Number of windows at top level. */
  1351. X
  1352. X#define    BANLM        21                /* Left margin of banner text. */
  1353. X#define    BANTEXT        "Crypt Breaker's Workbench"
  1354. X
  1355. X#define    DBLROW        2                /* Starting row of label. */
  1356. X#define    DBLCOL        9                /* Column where block number starts. */
  1357. X#define    DBSROW        (DBLROW+1)        /* Decryption Block. */
  1358. X#define    DBWIDTH        65                /* Decrypted block. */
  1359. X#define    DBHEIGHT    11                /* Decrytped block, not incl label. */
  1360. X#define    DBLTEXT        "Block -"        /* Label for decrypted block. */
  1361. X
  1362. X#define GBLROW        (DBSROW+DBHEIGHT)    /* Guess block label row. */
  1363. X#define    GBSROW        (GBLROW+1)        /* Guess block storage row. */
  1364. X#define    GBWIDTH        DBWIDTH            /* Width of same. */
  1365. X#define GBHEIGHT    6                /* Height of same. */
  1366. X#define    GBLTEXT        "Guess Window"    /* Label for guess block. */
  1367. X
  1368. X#define    WEBROW        DBLROW            /* Starting row of history */
  1369. X#define    WEBCOL        (DBWIDTH+1)        /* Starting column */
  1370. X#define    WEBWIDTH    (MAXWIDTH-DBWIDTH)        /* Decision history. */
  1371. X#define    WEBHEIGHT    (DBHEIGHT+GBHEIGHT+2)    /* Includes a title line. */
  1372. X
  1373. X#define USRROW        (GBSROW+GBHEIGHT)    /* User I/O area. */
  1374. X#define USRSCOL        10                /* Starting column of status msgs. */
  1375. X#define USRHEIGHT    (MAXHEIGHT-(GBHEIGHT+1)-(DBHEIGHT+1)-(1))
  1376. X/* total - guess block and title - decrypt block and title - banner */
  1377. X#define USRWIDTH    MAXWIDTH        /* Width of I/O window. */
  1378. END_OF_layout.h
  1379. if test 1450 -ne `wc -c <layout.h`; then
  1380.     echo shar: \"layout.h\" unpacked with wrong size!
  1381. fi
  1382. # end of overwriting check
  1383. fi
  1384. if test -f mss-prob-printout.txt -a "${1}" != "-c" ; then 
  1385.   echo shar: Will not over-write existing file \"mss-prob-printout.txt\"
  1386. else
  1387. echo shar: Extracting \"mss-prob-printout.txt\" \(2266 characters\)
  1388. sed "s/^X//" >mss-prob-printout.txt <<'END_OF_mss-prob-printout.txt'
  1389. Xsingle letter frequencies
  1390. X
  1391. XExpected value of prob is 0.313350.  Variance is 0.156338.
  1392. X
  1393. X 0.0000  0.0000  0.0000  0.0000  0.0000  0.0000  0.0000  0.0000 
  1394. X 0.0000  0.2167  0.2167  0.0000  0.2167  0.2167  0.0000  0.0000 
  1395. X 0.0000  0.0000  0.0000  0.0000  0.0000  0.0000  0.0000  0.0000 
  1396. X 0.0000  0.0000  0.0000  0.0000  0.0000  0.0000  0.0000  0.0000 
  1397. X 0.2167  0.0140  0.0040  0.0034  0.0034  0.0034  0.0034  0.0040 
  1398. X 0.0032  0.0052  0.0034  0.0034  0.0140  0.0103  0.0140  0.0004 
  1399. X 0.0342  0.0342  0.0342  0.0342  0.0342  0.0342  0.0342  0.0342 
  1400. X 0.0342  0.0342  0.0140  0.0140  0.0032  0.0034  0.0052  0.0140 
  1401. X 0.0034  0.0558  0.0127  0.0239  0.0270  0.0904  0.0136  0.0166 
  1402. X 0.0342  0.0496  0.0013  0.0039  0.0324  0.0195  0.0456  0.0526 
  1403. X 0.0162  0.0008  0.0423  0.0480  0.0652  0.0210  0.0073  0.0133 
  1404. X 0.0027  0.0119  0.0007  0.0032  0.0004  0.0052  0.0034  0.0103 
  1405. X 0.0040  0.0558  0.0127  0.0239  0.0270  0.0904  0.0136  0.0166 
  1406. X 0.0342  0.0496  0.0013  0.0039  0.0324  0.0195  0.0456  0.0526 
  1407. X 0.0162  0.0008  0.0423  0.0480  0.0652  0.0210  0.0073  0.0133 
  1408. X 0.0027  0.0119  0.0007  0.0032  0.0034  0.0052  0.0034  0.0000 
  1409. X
  1410. XExpected value of logprob is -3.623789.  Variance is 18.575068.
  1411. XLog of single letter frequencies
  1412. X
  1413. X-4.7974 -4.7974 -4.7974 -4.7974 -4.7974 -4.7974 -4.7974 -4.7974 
  1414. X-4.7974 -0.6641 -0.6641  0.0000 -0.6641 -0.6641 -4.7974 -4.7974 
  1415. X-4.7974 -4.7974 -4.7974 -4.7974 -4.7974 -4.7974 -4.7974 -4.7974 
  1416. X-4.7974 -4.7974 -4.7974 -4.7974 -4.7974 -4.7974 -4.7974 -4.7974 
  1417. X-0.6641 -1.8534 -2.4012 -2.4690 -2.4690 -2.4690 -2.4690 -2.4012 
  1418. X-2.4899 -2.2815 -2.4690 -2.4690 -1.8534 -1.9865 -1.8534 -3.4550 
  1419. X-1.4664 -1.4664 -1.4664 -1.4664 -1.4664 -1.4664 -1.4664 -1.4664 
  1420. X-1.4664 -1.4664 -1.8534 -1.8534 -2.4899 -2.4690 -2.2815 -1.8534 
  1421. X-2.4690 -1.2536 -1.8970 -1.6219 -1.5682 -1.0437 -1.8680 -1.7800 
  1422. X-1.4662 -1.3041 -2.8783 -2.4065 -1.4891 -1.7100 -1.3410 -1.2786 
  1423. X-1.7892 -3.1162 -1.3733 -1.3191 -1.1855 -1.6768 -2.1384 -1.8768 
  1424. X-2.5747 -1.9247 -3.1442 -2.4899 -3.4550 -2.2815 -2.4690 -1.9865 
  1425. X-2.4012 -1.2536 -1.8970 -1.6219 -1.5682 -1.0437 -1.8680 -1.7800 
  1426. X-1.4662 -1.3041 -2.8783 -2.4065 -1.4891 -1.7100 -1.3410 -1.2786 
  1427. X-1.7892 -3.1162 -1.3733 -1.3191 -1.1855 -1.6768 -2.1384 -1.8768 
  1428. X-2.5747 -1.9247 -3.1442 -2.4899 -2.4690 -2.2815 -2.4690 -4.7974 
  1429. END_OF_mss-prob-printout.txt
  1430. if test 2266 -ne `wc -c <mss-prob-printout.txt`; then
  1431.     echo shar: \"mss-prob-printout.txt\" unpacked with wrong size!
  1432. fi
  1433. # end of overwriting check
  1434. fi
  1435. if test -f mss.stats -a "${1}" != "-c" ; then 
  1436.   echo shar: Will not over-write existing file \"mss.stats\"
  1437. else
  1438. echo shar: Extracting \"mss.stats\" \(812 characters\)
  1439. sed "s/^X//" >mss.stats <<'END_OF_mss.stats'
  1440. X211123
  1441. X
  1442. X45 \000
  1443. X0 \001
  1444. X0 \002
  1445. X0 \003
  1446. X0 \004
  1447. X0 \005
  1448. X0 \006
  1449. X0 \007
  1450. X0 \b
  1451. X826 \t
  1452. X5539 \n
  1453. X0 \013
  1454. X0 \p
  1455. X0 \r
  1456. X0 \016
  1457. X0 \017
  1458. X0 \020
  1459. X0 \021
  1460. X0 \022
  1461. X0 \023
  1462. X0 \024
  1463. X0 \025
  1464. X0 \026
  1465. X0 \027
  1466. X0 \030
  1467. X0 \031
  1468. X0 \032
  1469. X0 \033
  1470. X0 \034
  1471. X0 \035
  1472. X0 \036
  1473. X0 \037
  1474. X36061  
  1475. X7 !
  1476. X502 "
  1477. X46 #
  1478. X268 $
  1479. X773 %
  1480. X31 &
  1481. X102 '
  1482. X1378 (
  1483. X1378 )
  1484. X106 *
  1485. X65 +
  1486. X1585 ,
  1487. X519 -
  1488. X1980 .
  1489. X61 /
  1490. X267 0
  1491. X551 1
  1492. X278 2
  1493. X120 3
  1494. X136 4
  1495. X140 5
  1496. X96 6
  1497. X65 7
  1498. X84 8
  1499. X96 9
  1500. X594 :
  1501. X61 ;
  1502. X211 <
  1503. X464 =
  1504. X204 >
  1505. X38 ?
  1506. X1785 @
  1507. X422 A
  1508. X157 B
  1509. X222 C
  1510. X296 D
  1511. X532 E
  1512. X190 F
  1513. X51 G
  1514. X133 H
  1515. X406 I
  1516. X31 J
  1517. X92 K
  1518. X228 L
  1519. X202 M
  1520. X280 N
  1521. X178 O
  1522. X308 P
  1523. X9 Q
  1524. X174 R
  1525. X417 S
  1526. X896 T
  1527. X142 U
  1528. X37 V
  1529. X143 W
  1530. X41 X
  1531. X91 Y
  1532. X2 Z
  1533. X738 [
  1534. X267 \\
  1535. X738 ]
  1536. X23 ^
  1537. X315 _
  1538. X1 `
  1539. X10370 a
  1540. X2389 b
  1541. X4918 c
  1542. X5538 d
  1543. X19962 e
  1544. X3405 f
  1545. X2781 g
  1546. X5595 h
  1547. X10833 i
  1548. X214 j
  1549. X496 k
  1550. X5735 l
  1551. X4371 m
  1552. X10902 n
  1553. X10866 o
  1554. X4123 p
  1555. X419 q
  1556. X9791 r
  1557. X9291 s
  1558. X13582 t
  1559. X4777 u
  1560. X1195 v
  1561. X1768 w
  1562. X824 x
  1563. X2453 y
  1564. X189 z
  1565. X26 {
  1566. X39 |
  1567. X26 }
  1568. X21 ~
  1569. X0 \177
  1570. X
  1571. END_OF_mss.stats
  1572. if test 812 -ne `wc -c <mss.stats`; then
  1573.     echo shar: \"mss.stats\" unpacked with wrong size!
  1574. fi
  1575. # end of overwriting check
  1576. fi
  1577. if test -f mss.words -a "${1}" != "-c" ; then 
  1578.   echo shar: Will not over-write existing file \"mss.words\"
  1579. else
  1580. echo shar: Extracting \"mss.words\" \(450 characters\)
  1581. sed "s/^X//" >mss.words <<'END_OF_mss.words'
  1582. X\n@Device
  1583. X@Device
  1584. X@device
  1585. X\n@device
  1586. X[Dover]
  1587. X[dover]
  1588. X(dover)
  1589. X\n@Style
  1590. X\n@style
  1591. X@Make
  1592. X@make
  1593. X\n@Make
  1594. X\n@make
  1595. X\n@Section
  1596. X\n@section
  1597. X\n@Subsection
  1598. X\n@SubSection
  1599. X\n@subsection
  1600. X\n@Center
  1601. X\n@center
  1602. X\n@Heading
  1603. X\n@MajorHeading
  1604. X\n@heading
  1605. X\n@majorheading
  1606. X\n@Begin
  1607. X\n@begin
  1608. X\n@End
  1609. X\n@end
  1610. X[Article]
  1611. X(Article)
  1612. X[Text]
  1613. X(Text)
  1614. X[article]
  1615. X(article)
  1616. X[text]
  1617. X(text)
  1618. Xtimesroman
  1619. XTimesRoman
  1620. XTimesroman
  1621. XHelvetica
  1622. Xhelvetica
  1623. Xfont
  1624. XFont
  1625. XIndent
  1626. Xindent
  1627. Xdouble
  1628. Xsingle
  1629. XDouble
  1630. XSingle
  1631. X
  1632. END_OF_mss.words
  1633. if test 450 -ne `wc -c <mss.words`; then
  1634.     echo shar: \"mss.words\" unpacked with wrong size!
  1635. fi
  1636. # end of overwriting check
  1637. fi
  1638. if test -f parser.c -a "${1}" != "-c" ; then 
  1639.   echo shar: Will not over-write existing file \"parser.c\"
  1640. else
  1641. echo shar: Extracting \"parser.c\" \(2096 characters\)
  1642. sed "s/^X//" >parser.c <<'END_OF_parser.c'
  1643. X/* 
  1644. X * Command completion and parsing routines.
  1645. X *
  1646. X * Robert W. Baldwin, December 1984.
  1647. X */
  1648. X
  1649. X
  1650. X#include    <stdio.h>
  1651. X#include    "window.h"
  1652. X#include    "specs.h"
  1653. X#include    "parser.h"
  1654. X
  1655. X
  1656. X/* Return TRUE if the cmdstring equals the model string up to and including
  1657. X * the first space.
  1658. X */
  1659. Xint    cmpword(model, cmdstring)
  1660. Xchar    *model, *cmdstring;
  1661. X{
  1662. X    while (*model != 0  &&  *cmdstring != 0) {
  1663. X        if (*model == *cmdstring  &&  *model == ' ')  return (TRUE);
  1664. X        if (*model != *cmdstring)  break;
  1665. X        model++;
  1666. X        cmdstring++;
  1667. X        }
  1668. X    if (*model == 0)  return(TRUE);
  1669. X    return(FALSE);
  1670. X}
  1671. X
  1672. X
  1673. X/* Return TRUE if the first word of the cmdstring is a substring
  1674. X * of the first word of model string.
  1675. X */
  1676. Xint    submatch(model, cmdstring)
  1677. Xchar    *model;
  1678. Xchar    *cmdstring;
  1679. X{
  1680. X    while (*model != 0  &&  *cmdstring != 0) {
  1681. X        if (*cmdstring == ' ')  break;
  1682. X        if (*model != *cmdstring)  return(FALSE);
  1683. X        if (*model == ' ')  break;
  1684. X        model++;
  1685. X        cmdstring++;
  1686. X        }
  1687. X
  1688. X    return(TRUE);
  1689. X}
  1690. X
  1691. X
  1692. X
  1693. X/* Lookup and perform a command from a command table.
  1694. X * If not found, return an error message.
  1695. X */
  1696. Xchar    *cmddo(cmdtab, cmdstring)
  1697. Xcmdent    *cmdtab;
  1698. Xchar    *cmdstring;
  1699. X{
  1700. X    for ( ; cmdtab->cmdname != 0 ; cmdtab++)  {
  1701. X        if (cmpword(cmdtab->cmdname, cmdstring))  {
  1702. X            return((*(cmdtab->cmdproc))(cmdstring));
  1703. X            }
  1704. X        }
  1705. X
  1706. X    return(CMDBAD);
  1707. X}
  1708. X
  1709. X
  1710. X
  1711. X/* Do automatic completion of the string based on the
  1712. X * command choices in the command table.
  1713. X * Be careful to avoid doubly expanding a string, by requiring that
  1714. X * the first few characters to match, but the whole word must not match.
  1715. X * If sucessful, return a pointer to the template string
  1716. X * in the command table.  Otherwise return NULL.
  1717. X */
  1718. Xchar    *cmdcomplete(cmdtab, cmdstring)
  1719. Xcmdent    *cmdtab;
  1720. Xchar    *cmdstring;
  1721. X{
  1722. X    cmdent    *centp;
  1723. X    char    *close;
  1724. X
  1725. X    for (centp = cmdtab ; centp->cmdname != 0 ; centp++)  {
  1726. X        if (cmpword(centp->cmdname, cmdstring))  {
  1727. X            return(NULL);    /* Has been expanded. */
  1728. X            }
  1729. X        }
  1730. X
  1731. X    close = NULL;
  1732. X    for (centp = cmdtab ; centp->cmdname != 0 ; centp++)  {
  1733. X        if (submatch(centp->cmdname, cmdstring))  {
  1734. X            if (close != NULL)  return(NULL);    /* Not yet unique. */
  1735. X            close = centp->cmdname;
  1736. X            }
  1737. X        }
  1738. X
  1739. X    return(close);
  1740. X}
  1741. END_OF_parser.c
  1742. if test 2096 -ne `wc -c <parser.c`; then
  1743.     echo shar: \"parser.c\" unpacked with wrong size!
  1744. fi
  1745. # end of overwriting check
  1746. fi
  1747. if test -f parser.h -a "${1}" != "-c" ; then 
  1748.   echo shar: Will not over-write existing file \"parser.h\"
  1749. else
  1750. echo shar: Extracting \"parser.h\" \(809 characters\)
  1751. sed "s/^X//" >parser.h <<'END_OF_parser.h'
  1752. X/*
  1753. X * Header for command parsing and completing routines.
  1754. X *
  1755. X * Robert W. Baldwin, December 1984.
  1756. X */
  1757. X
  1758. X
  1759. X
  1760. X#define    CMDBAD    "I don't know how to do that."
  1761. X
  1762. X
  1763. X/* A command table is an array of cmdent's terminated by a
  1764. X * cmdent that has a cmdname = NULL.
  1765. X * The command name can contain helpful noise words since
  1766. X * the comparision is only done on characters upto the first space.
  1767. X * The cmdproc is passed the full command string (including cmd name),
  1768. X * and returns a pointer to a status message.  The return pointer should
  1769. X * be NULL is everything goes ok.
  1770. X *
  1771. X * The command table should have atleast two non-empty entries for completion
  1772. X * to work properly.
  1773. X */
  1774. X
  1775. X#define    cmdent    struct xcmdent
  1776. X
  1777. Xstruct    xcmdent    {
  1778. X        char    *cmdname;    /* Comparison done up to first blank. */
  1779. X        char    *(*cmdproc)(/* cmd-string */);
  1780. X        };
  1781. END_OF_parser.h
  1782. if test 809 -ne `wc -c <parser.h`; then
  1783.     echo shar: \"parser.h\" unpacked with wrong size!
  1784. fi
  1785. # end of overwriting check
  1786. fi
  1787. if test -f pgate.c -a "${1}" != "-c" ; then 
  1788.   echo shar: Will not over-write existing file \"pgate.c\"
  1789. else
  1790. echo shar: Extracting \"pgate.c\" \(1250 characters\)
  1791. sed "s/^X//" >pgate.c <<'END_OF_pgate.c'
  1792. X/*
  1793. X * Routines to use knowledge of Zee to expand knowledge of Perms.
  1794. X *
  1795. X * Bob Baldwin, January 1985.
  1796. X */
  1797. X
  1798. X
  1799. X#include    <stdio.h>
  1800. X#include    "window.h"
  1801. X#include    "specs.h"
  1802. X
  1803. X
  1804. Xextern    int    kzee[];
  1805. Xextern    int    kzeeinv[];
  1806. X
  1807. X
  1808. X/* User command to propage info from Ai to Aj using Zee**(j-i).
  1809. X * Returns NULL if sucessful.
  1810. X */
  1811. Xchar *pgate(str)
  1812. Xchar    *str;
  1813. X{
  1814. X    FILE    *fd;
  1815. X    int        i;
  1816. X    int        k;
  1817. X    int        from, to;
  1818. X    int        *zeek, *zeeinvk;    /* Zee ** k */
  1819. X    int        *fromperm, *tmp1perm, *tmp2perm;
  1820. X    int        kexp[BLOCKSIZE+1], kexpinv[BLOCKSIZE+1];
  1821. X    int        ktmp1perm[BLOCKSIZE+1];
  1822. X    int        ktmp2perm[BLOCKSIZE+1];
  1823. X
  1824. X    tmp1perm = ktmp1perm;
  1825. X    tmp2perm = ktmp2perm;
  1826. X    zeek = kexp;
  1827. X    zeeinvk = kexpinv;
  1828. X    from = to = 0;
  1829. X
  1830. X    if ((i = sscanf(str,"%*[^:]: %d %*[^:]: %d", &from, &to)) != 2) {
  1831. X        return("Could not parse all the arguments.");
  1832. X        }
  1833. X
  1834. X    if (dbsgetblk(&dbstore) != to)
  1835. X        dbssetblk(&dbstore, to);
  1836. X
  1837. X    k = to - from;
  1838. X    if (k >= 0) {
  1839. X        expperm(kzee, zeek, k);
  1840. X        expperm(kzeeinv, zeeinvk, k);
  1841. X        }
  1842. X    else {
  1843. X        expperm(kzee, zeeinvk, -k);
  1844. X        expperm(kzeeinv, zeek, -k);
  1845. X        }
  1846. X
  1847. X    multperm(refperm(from), zeek, tmp1perm);
  1848. X    multperm(zeeinvk, tmp1perm, tmp2perm);
  1849. X
  1850. X    if (!dbsmerge(&dbstore, tmp2perm))  {
  1851. X        wl_rcursor(&user);
  1852. X        return("Merge conflicts with current plaintext.");
  1853. X        }
  1854. X
  1855. X    wl_rcursor(&user);
  1856. X    return(NULL);
  1857. X}
  1858. END_OF_pgate.c
  1859. if test 1250 -ne `wc -c <pgate.c`; then
  1860.     echo shar: \"pgate.c\" unpacked with wrong size!
  1861. fi
  1862. # end of overwriting check
  1863. fi
  1864. if test -f pqueue.c -a "${1}" != "-c" ; then 
  1865.   echo shar: Will not over-write existing file \"pqueue.c\"
  1866. else
  1867. echo shar: Extracting \"pqueue.c\" \(1661 characters\)
  1868. sed "s/^X//" >pqueue.c <<'END_OF_pqueue.c'
  1869. X/*
  1870. X * Priority queue.
  1871. X *
  1872. X * Bob Baldwin, February, 1985.
  1873. X */
  1874. X
  1875. X#include    <stdio.h>
  1876. X#include    "pqueue.h"
  1877. X
  1878. X
  1879. X
  1880. X/* Initialize a pqueue header with the given parameters.
  1881. X */
  1882. Xpque_init(pque_hdr, max_score, pque_tab, pque_size)
  1883. Xpqueue_hdr    *pque_hdr;
  1884. Xfloat        max_score;
  1885. Xpqueue_ent    *pque_tab;
  1886. Xint            pque_size;
  1887. X{
  1888. X    pque_hdr->next_index = 0;
  1889. X    pque_hdr->pque_size = pque_size;
  1890. X    pque_hdr->max_score = max_score;
  1891. X    pque_hdr->pque_tab = pque_tab;
  1892. X}
  1893. X
  1894. X
  1895. X/* Return TRUE if the pqueue cannot hold another entry.
  1896. X */
  1897. Xint    pque_full(pque_hdr)
  1898. Xpqueue_hdr    *pque_hdr;
  1899. X{
  1900. X    return (pque_hdr->next_index >= pque_hdr->pque_size);
  1901. X}
  1902. X
  1903. X
  1904. X/* Add an entry to the priority queue.  Sorted lowest score first.
  1905. X * The queue header indicates the next free slot, the maximum
  1906. X * score (all scores in queue < max), and the size of the table.
  1907. X * If the pqueue is full the lowest scoring entry will be
  1908. X * thrown out.
  1909. X *
  1910. X * Implementation:  Find the first slot before sizelast+1 that
  1911. X * has a size less than the size arg.  Shuffle down the list
  1912. X * to create a hole and insert the new entry.
  1913. X */
  1914. Xpque_add(pque_hdr, score, value1, value2)
  1915. Xpqueue_hdr    *pque_hdr;
  1916. Xfloat        score;
  1917. Xint            value1;
  1918. Xint            value2;
  1919. X{
  1920. X    int            k;        /* Slot where new entry will go. */
  1921. X    int            i;
  1922. X    pqueue_ent    *pque;
  1923. X    pqueue_ent    new_ent;
  1924. X
  1925. X    if (score >= pque_hdr->max_score)  return;
  1926. X
  1927. X    new_ent.score = score;
  1928. X    new_ent.value1 = value1;
  1929. X    new_ent.value2 = value2;
  1930. X    pque = pque_hdr->pque_tab;
  1931. X
  1932. X    for (k = 0 ; k < pque_hdr->next_index ; k++)  {
  1933. X        if (pque[k].score > score)  break;
  1934. X        }
  1935. X
  1936. X    for (i = pque_hdr->next_index ; i > k ; i--)  {
  1937. X        pque[i] = pque[i-1];
  1938. X        }
  1939. X    if (pque_hdr->next_index < pque_hdr->pque_size)
  1940. X        pque_hdr->next_index++;
  1941. X
  1942. X    pque[k] = new_ent;
  1943. X}
  1944. END_OF_pqueue.c
  1945. if test 1661 -ne `wc -c <pqueue.c`; then
  1946.     echo shar: \"pqueue.c\" unpacked with wrong size!
  1947. fi
  1948. # end of overwriting check
  1949. fi
  1950. if test -f pqueue.h -a "${1}" != "-c" ; then 
  1951.   echo shar: Will not over-write existing file \"pqueue.h\"
  1952. else
  1953. echo shar: Extracting \"pqueue.h\" \(555 characters\)
  1954. sed "s/^X//" >pqueue.h <<'END_OF_pqueue.h'
  1955. X/*
  1956. X * Priority queue declarations.
  1957. X *
  1958. X * Bob Baldwin, February, 1985.
  1959. X */
  1960. X
  1961. Xextern    int        pque_full(/* pque_hdr */);
  1962. Xextern            pque_add(/* pque_hdr */);
  1963. Xextern            pque_init(/* pque_hdr, min_score, pque_tab, pque_size */);
  1964. X
  1965. X#define    pqueue_ent    struct xpqueue_ent
  1966. Xpqueue_ent    {
  1967. X        float    score;
  1968. X        int        value1;
  1969. X        int        value2;
  1970. X        };
  1971. X
  1972. X#define    pqueue_hdr    struct xpqueue_hdr
  1973. Xpqueue_hdr    {
  1974. X        int            next_index;        /* Next free entry. */
  1975. X        int            pque_size;        /* Number of entries. */
  1976. X        float        max_score;        /* Score < max */
  1977. X        pqueue_ent    *pque_tab;        /* Ptr to first entry. */
  1978. X        };
  1979. END_OF_pqueue.h
  1980. if test 555 -ne `wc -c <pqueue.h`; then
  1981.     echo shar: \"pqueue.h\" unpacked with wrong size!
  1982. fi
  1983. # end of overwriting check
  1984. fi
  1985. if test -f sdriver.c -a "${1}" != "-c" ; then 
  1986.   echo shar: Will not over-write existing file \"sdriver.c\"
  1987. else
  1988. echo shar: Extracting \"sdriver.c\" \(2099 characters\)
  1989. sed "s/^X//" >sdriver.c <<'END_OF_sdriver.c'
  1990. X/*
  1991. X * Test driver for scoring stuff
  1992. X */
  1993. X
  1994. X#include    <stdio.h>
  1995. X#include    <math.h>
  1996. X#include    "window.h"
  1997. X#include    "specs.h"
  1998. X#include    "cipher.h"
  1999. X
  2000. X
  2001. Xextern    str2gsi();
  2002. X
  2003. Xgsinfo    mygsi;
  2004. Xint        kwnbuf[100], gssbuf[100];
  2005. X
  2006. X/* Test routine for statistics. */
  2007. Xmain(argc, argv)
  2008. Xint        argc;
  2009. Xchar    *argv[];
  2010. X{
  2011. X    char    *p;
  2012. X    int        c, i;
  2013. X    float    h;
  2014. X    char    plainbuf[BLOCKSIZE+1];
  2015. X    int        pvec[BLOCKSIZE+1];
  2016. X    float    pscore, fscore;
  2017. X    int        length;
  2018. X    gsinfo    *gsi;
  2019. X    char    str[100];
  2020. X
  2021. X    printf("\nStatistics Test driver.  Type a line to see its score.\n\n");
  2022. X
  2023. X    load_1stats_from("mss.stats");
  2024. X    load_2stats_from("mss-bigram.stats");
  2025. X
  2026. X    gsi = &mygsi;
  2027. X    gsi->cknown = kwnbuf;
  2028. X    gsi->cguessed = gssbuf;
  2029. X
  2030. X    while (TRUE) {
  2031. X        length = 0;
  2032. X        for (p = plainbuf ; (c=read_char(stdin)) != EOL ; *p++ = c )  {
  2033. X            length++;
  2034. X            }
  2035. X        *p = NULL;
  2036. X
  2037. X        stripdots(plainbuf, str);
  2038. X        str2pvec(str, pvec);
  2039. X        pscore = pvec_1score(pvec);
  2040. X        printf("pvec_1score is %5.3f", pscore);
  2041. X/*
  2042. X        pscore = var_1score(pvec);
  2043. X        printf("var_1score is %5.3f", pscore);
  2044. X
  2045. X        pscore = prob_1score(pvec);
  2046. X        printf(", and prob_1score is %.3e", pscore);
  2047. X*/
  2048. X
  2049. X        str2gsi(plainbuf, gsi);
  2050. X        pscore = gsi_score(gsi);
  2051. X        printf(", and gsi_score is %5.3f", pscore);
  2052. X
  2053. X        printf("\n");
  2054. X        }
  2055. X}
  2056. X
  2057. X
  2058. X/* Fill in guess info block from string.  Treat all chars as
  2059. X * consecutive, except "." means unknown.
  2060. X */
  2061. Xstr2gsi(str, gsi)
  2062. Xchar    *str;
  2063. Xgsinfo    *gsi;
  2064. X{
  2065. X    int        cpos_index, guessed_index;
  2066. X
  2067. X    cpos_index = 0;
  2068. X    guessed_index = 0;
  2069. X    while (*str != NULL)  {
  2070. X        if (*str == '.')  {
  2071. X            (gsi->cguessed)[guessed_index] = NONE;
  2072. X            }
  2073. X        else {
  2074. X            gsi->cpos[cpos_index] = guessed_index;
  2075. X            cpos_index++;
  2076. X            (gsi->cguessed)[guessed_index] = 0377 & (*str);
  2077. X            }
  2078. X        (gsi->cknown)[guessed_index] = NONE;
  2079. X        guessed_index++;
  2080. X        str++;
  2081. X        }
  2082. X    gsi->cpos[cpos_index] = NONE;
  2083. X    (gsi->cknown)[guessed_index] = NONE;
  2084. X    (gsi->cguessed)[guessed_index] = NONE;
  2085. X}
  2086. X
  2087. X/* Copy in to out deleting the character "."
  2088. X */
  2089. Xstripdots(in, out)
  2090. Xchar    *in, *out;        /* Null terminated strings. */
  2091. X{
  2092. X    while (*in != NULL)  {
  2093. X        if (*in != '.')
  2094. X            *out++ = *in++;
  2095. X        else
  2096. X            in++;
  2097. X        }
  2098. X    *out = NULL;
  2099. X}
  2100. X
  2101. X
  2102. Xkey    u_getkey()
  2103. X{
  2104. X}
  2105. X
  2106. Xkeyer    topktab[] ={{0, NULL}};
  2107. X
  2108. X
  2109. Xchar    *quitcmd()
  2110. X{
  2111. X    exit(0);
  2112. X}
  2113. END_OF_sdriver.c
  2114. if test 2099 -ne `wc -c <sdriver.c`; then
  2115.     echo shar: \"sdriver.c\" unpacked with wrong size!
  2116. fi
  2117. # end of overwriting check
  2118. fi
  2119. if test -f short.words -a "${1}" != "-c" ; then 
  2120.   echo shar: Will not over-write existing file \"short.words\"
  2121. else
  2122. echo shar: Extracting \"short.words\" \(65 characters\)
  2123. sed "s/^X//" >short.words <<'END_OF_short.words'
  2124. X an 
  2125. X on 
  2126. X of 
  2127. X if 
  2128. X is 
  2129. X in 
  2130. X it 
  2131. X at 
  2132. X as 
  2133. X to 
  2134. X so 
  2135. X by 
  2136. X be 
  2137. END_OF_short.words
  2138. if test 65 -ne `wc -c <short.words`; then
  2139.     echo shar: \"short.words\" unpacked with wrong size!
  2140. fi
  2141. # end of overwriting check
  2142. fi
  2143. if test -f stats.slice -a "${1}" != "-c" ; then 
  2144.   echo shar: Will not over-write existing file \"stats.slice\"
  2145. else
  2146. echo shar: Extracting \"stats.slice\" \(182 characters\)
  2147. sed "s/^X//" >stats.slice <<'END_OF_stats.slice'
  2148. Xset cbwdir=`pwd`
  2149. Xsetenv LETTERSTATS ${cbwdir}/mss.stats
  2150. Xsetenv BIGRAMSTATS ${cbwdir}/mss-bigram.stats
  2151. Xsetenv TRIGRAMSTATS ${cbwdir}/trigrams.stats
  2152. Xsetenv DICTIONARY /usr/dict/words
  2153. X
  2154. END_OF_stats.slice
  2155. if test 182 -ne `wc -c <stats.slice`; then
  2156.     echo shar: \"stats.slice\" unpacked with wrong size!
  2157. fi
  2158. # end of overwriting check
  2159. fi
  2160. if test -f test3.words -a "${1}" != "-c" ; then 
  2161.   echo shar: Will not over-write existing file \"test3.words\"
  2162. else
  2163. echo shar: Extracting \"test3.words\" \(223 characters\)
  2164. sed "s/^X//" >test3.words <<'END_OF_test3.words'
  2165. Xbandwidth
  2166. Xhome
  2167. Xcable
  2168. Xpersonal
  2169. X personal
  2170. X\npersonal
  2171. X home or
  2172. Xcomputer
  2173. X computer
  2174. X\ncomputer
  2175. Xbusiness
  2176. X business
  2177. X\nbusiness
  2178. Xcommunication
  2179. X communication
  2180. X\ncommunication
  2181. XLAN
  2182. X LAN
  2183. X\nLAN
  2184. Xfiber
  2185. X fiber
  2186. X\nfiber
  2187. Xoptic
  2188. X optic
  2189. X\noptic
  2190. X
  2191. END_OF_test3.words
  2192. if test 223 -ne `wc -c <test3.words`; then
  2193.     echo shar: \"test3.words\" unpacked with wrong size!
  2194. fi
  2195. # end of overwriting check
  2196. fi
  2197. if test -f trigrams.short -a "${1}" != "-c" ; then 
  2198.   echo shar: Will not over-write existing file \"trigrams.short\"
  2199. else
  2200. echo shar: Extracting \"trigrams.short\" \(171 characters\)
  2201. sed "s/^X//" >trigrams.short <<'END_OF_trigrams.short'
  2202. X100362
  2203. X
  2204. X1532    the
  2205. X 500    The
  2206. X 747    ing
  2207. X 667    and
  2208. X 547    her
  2209. X 448    ere
  2210. X 376    ent
  2211. X 353    tha
  2212. X 336    was
  2213. X 312    eth
  2214. X 306    for
  2215. X 298    hat
  2216. X 281    she
  2217. X 227    ion
  2218. X 274    int
  2219. X 264    his
  2220. X 252    ers
  2221. X 190    ure
  2222. X
  2223. END_OF_trigrams.short
  2224. if test 171 -ne `wc -c <trigrams.short`; then
  2225.     echo shar: \"trigrams.short\" unpacked with wrong size!
  2226. fi
  2227. # end of overwriting check
  2228. fi
  2229. if test -f trigrams.stats -a "${1}" != "-c" ; then 
  2230.   echo shar: Will not over-write existing file \"trigrams.stats\"
  2231. else
  2232. echo shar: Extracting \"trigrams.stats\" \(548 characters\)
  2233. sed "s/^X//" >trigrams.stats <<'END_OF_trigrams.stats'
  2234. X62721
  2235. X
  2236. X1377       
  2237. X1098     th
  2238. X607    the
  2239. X300 The
  2240. X699    he 
  2241. X473    .  
  2242. X357    to 
  2243. X344     to
  2244. X338     of
  2245. X332    of 
  2246. X338    ing
  2247. X307     an
  2248. X305    is 
  2249. X299    ed 
  2250. X288      t
  2251. X257    and
  2252. X247    ng 
  2253. X222     a 
  2254. X211     in
  2255. X210     is
  2256. X204    er 
  2257. X204    re 
  2258. X191    es 
  2259. X186    ion
  2260. X178    at 
  2261. X173     be
  2262. X169    s. 
  2263. X168    tio
  2264. X157     wh
  2265. X155    ent
  2266. X153    hat
  2267. X150    con
  2268. X144     re
  2269. X143    se 
  2270. X138    or 
  2271. X137    as 
  2272. X132    en 
  2273. X131    on 
  2274. X128    tha
  2275. X128    in 
  2276. X126    ly 
  2277. X124    thi
  2278. X119    for
  2279. X119     pr
  2280. X117    ate
  2281. X117    her
  2282. X117     ar
  2283. X117    are
  2284. X115    ch 
  2285. X115    \n\n@
  2286. X114     so
  2287. X115     fo
  2288. X113    pro
  2289. X112    lay
  2290. X112    all
  2291. X111     wi
  2292. X109    ati
  2293. X109    le 
  2294. X108    al 
  2295. X108     ha
  2296. X107    ver
  2297. X105     we
  2298. X104     la
  2299. X104    age
  2300. X102    an 
  2301. X102    his
  2302. X101    ere
  2303. X
  2304. END_OF_trigrams.stats
  2305. if test 548 -ne `wc -c <trigrams.stats`; then
  2306.     echo shar: \"trigrams.stats\" unpacked with wrong size!
  2307. fi
  2308. # end of overwriting check
  2309. fi
  2310. if test -f tritab.c -a "${1}" != "-c" ; then 
  2311.   echo shar: Will not over-write existing file \"tritab.c\"
  2312. else
  2313. echo shar: Extracting \"tritab.c\" \(3020 characters\)
  2314. sed "s/^X//" >tritab.c <<'END_OF_tritab.c'
  2315. X/*
  2316. X * Operations to load and print the table of trigrams.
  2317. X */
  2318. X
  2319. X#include    <math.h>
  2320. X#include    <stdio.h>
  2321. X#include    "window.h"
  2322. X#include    "specs.h"
  2323. X#include    "cipher.h"
  2324. X#include    "autotri.h"
  2325. X
  2326. X
  2327. X
  2328. X#define    DEFAULTTRIGLIST    "trigrams.txt"
  2329. Xint        trig_loaded = FALSE;
  2330. X
  2331. X/* This number is the probability that a randomly selected trigram
  2332. X * is not in the table of trigrams.
  2333. X */
  2334. Xfloat    trig_other_prob;
  2335. X
  2336. X
  2337. X/* Table of trigrams with their probabilities.
  2338. X * The last entry has trig_ent.trigram == NULL.
  2339. X * This table is also be used as a priority queue.
  2340. X */
  2341. Xint            trig_tab_next;            /* For priority queue. */
  2342. Xtrig_ent    trig_tab[TRIGTABSZ];
  2343. X
  2344. X
  2345. X
  2346. X/* The following buffer is used to store all the trigram
  2347. X * strings read from the file.
  2348. X * trig_buf_next points to the net free character.
  2349. X */
  2350. Xchar    *trig_buf_next;
  2351. Xchar    trig_buf[TRIGBUFSZ];
  2352. X
  2353. X
  2354. X
  2355. X/* Load the trigram table from the named file.
  2356. X */
  2357. Xload_tri_from(filename)
  2358. Xchar    *filename;
  2359. X{
  2360. X    FILE    *inp;
  2361. X
  2362. X    if ((inp = fopen(filename, "r")) == NULL)  {
  2363. X        printf("\nCannot open %s to read trigram stats.\n", filename);
  2364. X        exit(0);
  2365. X        }
  2366. X    load_tri(inp);
  2367. X    fclose(inp);
  2368. X}
  2369. X
  2370. X
  2371. X/* Load trigram table from the given stream.
  2372. X * Input format:
  2373. X * <Total number of trigrams>
  2374. X * <blank line>
  2375. X * <Count for a particular trigram><space><Chars in the particular trigram>
  2376. X * ...
  2377. X * <Count for a particular trigram><space><Chars in the particular trigram>
  2378. X * <blank line>
  2379. X * <End of file>
  2380. X */
  2381. Xload_tri(inp)
  2382. XFILE    *inp;
  2383. X{
  2384. X    int        i,n;
  2385. X    int        tmp;
  2386. X    int        c;
  2387. X    float    v, trigram_prob;
  2388. X    float    etotal, ctotal;
  2389. X    char    *trigram_start;
  2390. X
  2391. X    trig_loaded = TRUE;
  2392. X    trig_tab_next = 0;
  2393. X    trig_buf_next = trig_buf;
  2394. X    trig_other_prob = 1.0;
  2395. X    trig_tab[0].trigram = NULL;
  2396. X
  2397. X    if (fscanf(inp, "%d", &tmp) != 1)  {
  2398. X        printf("\nError while getting total trigram count.\n");
  2399. X        exit(0);
  2400. X        }
  2401. X    etotal = tmp;
  2402. X    ctotal = 0.0;
  2403. X
  2404. X    if (fscanf(inp, "\n") != 0)  {
  2405. X        printf("\nError while skipping blank line in trigram file.\n");
  2406. X        return;
  2407. X        }
  2408. X
  2409. X    while (TRUE) {
  2410. X        if ((n = fscanf(inp, "%d", &tmp)) != 1)  {
  2411. X            if (n == 0) break;
  2412. X            if (n == EOF) break;
  2413. X            printf("\nError getting character count from trigram file.\n ");
  2414. X            return;
  2415. X            }
  2416. X        v = tmp;
  2417. X        ctotal += v;
  2418. X        trigram_prob = v/etotal;
  2419. X        trig_other_prob -= trigram_prob;
  2420. X
  2421. X        c = read_char(inp);        /* Skip the space. */
  2422. X        trigram_start = trig_buf_next;
  2423. X        while (TRUE) {
  2424. X            c = read_char(inp);
  2425. X            if (c == EOL)  break;
  2426. X            if (trig_buf_next >= &trig_buf[TRIGBUFSZ-1]) {
  2427. X                printf("\nOverflowed Trigram buffer.\n");
  2428. X                exit(0);
  2429. X                }
  2430. X            *trig_buf_next++ = c & CHARMASK;
  2431. X            }
  2432. X        if (trig_buf_next >= &trig_buf[TRIGBUFSZ-1]) {
  2433. X            printf("\nOverflowed Trigram buffer.\n");
  2434. X            exit(0);
  2435. X            }
  2436. X        *trig_buf_next++ = NULL;
  2437. X
  2438. X        trig_tab[trig_tab_next].prob = trigram_prob;
  2439. X        trig_tab[trig_tab_next].trigram = trigram_start;
  2440. X        trig_tab[trig_tab_next].notused = 0;
  2441. X        trig_tab_next++;
  2442. X        }
  2443. X
  2444. X}
  2445. X
  2446. X
  2447. X/* Print the trigram table onto a stream.
  2448. X */
  2449. Xprint_tri(out)
  2450. XFILE    *out;
  2451. X{
  2452. X    int        i;
  2453. X
  2454. X    fprintf(out, "\n");
  2455. X    for (i = 0 ; trig_tab[i].trigram != NULL ; i++)  {
  2456. X        fprintf(out, "'%s'\t%7.4f\n", trig_tab[i].trigram, trig_tab[i].prob);
  2457. X        }
  2458. X    fprintf(out, "\n");
  2459. X}
  2460. END_OF_tritab.c
  2461. if test 3020 -ne `wc -c <tritab.c`; then
  2462.     echo shar: \"tritab.c\" unpacked with wrong size!
  2463. fi
  2464. # end of overwriting check
  2465. fi
  2466. if test -f vt100.slice -a "${1}" != "-c" ; then 
  2467.   echo shar: Will not over-write existing file \"vt100.slice\"
  2468. else
  2469. echo shar: Extracting \"vt100.slice\" \(947 characters\)
  2470. sed "s/^X//" >vt100.slice <<'END_OF_vt100.slice'
  2471. X# vt100 terminal info file for CBW.
  2472. X#
  2473. X# Set the termcap explicitly since many sites have weak /etc/termcap files.
  2474. Xsetenv TERMCAP 'd1|vt100v|vt100 in vt52 mode:\
  2475. X    :ce=3\EK:sf=2\n:sr=2\EI:cs=\E<\E[%i%2;%2r\E[?2l:\
  2476. X    :so=2\E<\E[7m:se=2\E[m\E[?2l:us=2\E<\E[4m:ue=2\E[m\E[?2l:\
  2477. X    :is=\E<\E[m\E>\E[?3;4;6;7l\E[?2l\200\200\200\200\200\200\200\200:\
  2478. X    :dN#4:\
  2479. X    :cr=^M:do=^J:nl=^J:bl=^G:\
  2480. X    :le=^H:bs:cd=\EJ:ce=\EK:cl=\EH\EJ:cm=\EY%+ %+ :co#80:li#24:nd=\EC:\
  2481. X    :ta=^I:pt:sr=\EI:up=\EA:ku=\EA:kd=\EB:kr=\EC:kl=\ED:kb=^H:\
  2482. X    :as=\EF:ae=\EG:ks=:ke=:k1=\EP:k2=\EQ:k3=\ER:k4=\ES:'
  2483. X
  2484. X#
  2485. X# Keystroke command map.
  2486. X# No need to set this.
  2487. X#
  2488. X# setenv KEYMAP ''
  2489. X
  2490. X#
  2491. X# For GRAPHICSMAP, the first char must be one of the following:
  2492. X# \G - graphics mode
  2493. X# \N - normal mode
  2494. X# \S - standout (inverse) mode
  2495. X# The remaining positions use the regular slash codes.
  2496. X#
  2497. Xsetenv GRAPHICSMAP 'tb=\Gb:lf=\Ge:cr=\Gd:\
  2498. X           :na=\G'\`':ff=\Gc:cc=\Gf:uk=\G~:ul=\Go:\
  2499. X           :hb=\Gq:vb=\Gx:ll=\Gm:'
  2500. X
  2501. END_OF_vt100.slice
  2502. if test 947 -ne `wc -c <vt100.slice`; then
  2503.     echo shar: \"vt100.slice\" unpacked with wrong size!
  2504. fi
  2505. # end of overwriting check
  2506. fi
  2507. if test -f zeecode.c -a "${1}" != "-c" ; then 
  2508.   echo shar: Will not over-write existing file \"zeecode.c\"
  2509. else
  2510. echo shar: Extracting \"zeecode.c\" \(2181 characters\)
  2511. sed "s/^X//" >zeecode.c <<'END_OF_zeecode.c'
  2512. X/*
  2513. X * Encryption/Decrytion program based on crypt but uses A0 and Zee
  2514. X * rather than Rotor and Reflector.
  2515. X *
  2516. X * Robert W. Baldwin, December 1984.
  2517. X */
  2518. X
  2519. X
  2520. X#include    <stdio.h>
  2521. X
  2522. X
  2523. X#define    BLOCKSIZE    256
  2524. X#define    MODMASK        (BLOCKSIZE-1)
  2525. X#define    FALSE        0
  2526. X#define    TRUE        1
  2527. X
  2528. X
  2529. X/* Global state. */
  2530. X
  2531. Xint        perm[BLOCKSIZE];    /* Current A permutation. */
  2532. Xint        nxtperm[BLOCKSIZE];    /* Next A permutation. */
  2533. Xint        zee[BLOCKSIZE];        /* Zee permutation. */
  2534. Xint        zeeinv[BLOCKSIZE];    /* Inverse of Zee permutation. */
  2535. X
  2536. X
  2537. Xchar    *permfile = "zeecode.perm";
  2538. X
  2539. X
  2540. X/* Do the deed.
  2541. X */
  2542. Xmain()
  2543. X{
  2544. X    int    i;
  2545. X    int    *curperm;
  2546. X    FILE *fd;
  2547. X
  2548. X    if ((fd = fopen(permfile, "r")) == NULL)  {
  2549. X        printf("\nCould not open %s to read permutations.\n", permfile);
  2550. X        exit(0);
  2551. X        }
  2552. X
  2553. X    readblock(fd, zee);
  2554. X    for (i = 0 ; i < BLOCKSIZE ; i++)  zeeinv[zee[i]] = i;
  2555. X    readblock(fd, perm);
  2556. X
  2557. X    fclose(fd);
  2558. X
  2559. X    while (doblock(perm))  {
  2560. X        pgate(perm, nxtperm, zee, zeeinv);
  2561. X        for (i = 0 ; i < BLOCKSIZE ; i++)  perm[i] = nxtperm[i];
  2562. X        }
  2563. X}
  2564. X
  2565. X
  2566. X/* Compute the permutation after inperm using z and its inverse zi.
  2567. X * The result is placed in outperm.
  2568. X */
  2569. Xpgate(inperm, outperm, z, zi)
  2570. Xint    *inperm;
  2571. Xint    *outperm;
  2572. Xint    *z;
  2573. Xint    *zi;
  2574. X{
  2575. X    int        i,x,v;
  2576. X    int        w;
  2577. X
  2578. X    for (i = 0 ; i < BLOCKSIZE ; i++) {
  2579. X        w = -1;
  2580. X        x = z[i];
  2581. X        if (x != -1) {
  2582. X            v = inperm[x&MODMASK];
  2583. X            if (v != -1)
  2584. X                w = zi[v&MODMASK];
  2585. X            }
  2586. X        outperm[i] = w;
  2587. X        }
  2588. X}
  2589. X
  2590. X
  2591. X/* Read character from stdin, encrypt them with the given permutation, p,
  2592. X * and write them to stdout.
  2593. X * Return FALSE if reach end of file.
  2594. X */
  2595. Xdoblock(p)
  2596. Xint    p[];
  2597. X{
  2598. X    int        pos;
  2599. X    int        sc;
  2600. X    char    c;
  2601. X
  2602. X    for (pos = 0 ; pos < BLOCKSIZE ; pos++) {
  2603. X        if ((c=getchar()) == EOF)  return(FALSE);
  2604. X        sc = p[MODMASK&(c+pos)];
  2605. X        if (sc == -1)  {putchar('?');}
  2606. X        else  {putchar(MODMASK & (sc - pos));}
  2607. X        }
  2608. X    return(TRUE);
  2609. X}
  2610. X
  2611. X
  2612. X/* Read a block of BLOCKSIZE integers into the given buffer from
  2613. X * the given stream.
  2614. X * The block is terminated by a newline character.
  2615. X */
  2616. Xreadblock(fd, buf)
  2617. XFILE    *fd;
  2618. Xint        buf[];
  2619. X{
  2620. X    int    i;
  2621. X
  2622. X    for (i = 0 ; i < BLOCKSIZE ; i++) {
  2623. X        if (fscanf(fd, "%3d ", &buf[i]) != 1)  {
  2624. X            printf("\nReadblock error on i = %d\n", i);
  2625. X            exit(0);
  2626. X            }
  2627. X        }
  2628. X    if (fscanf(fd, "\n") != 0)  {
  2629. X        printf("\nReadblock error on newline\n");
  2630. X        exit(0);
  2631. X        }
  2632. X}
  2633. END_OF_zeecode.c
  2634. if test 2181 -ne `wc -c <zeecode.c`; then
  2635.     echo shar: \"zeecode.c\" unpacked with wrong size!
  2636. fi
  2637. # end of overwriting check
  2638. fi
  2639. echo shar: End of archive 1 \(of 11\).
  2640. cp /dev/null ark1isdone
  2641. MISSING=""
  2642. for I in 1 2 3 4 5 6 7 8 9 10 11 ; do
  2643.     if test ! -f ark${I}isdone ; then
  2644.     MISSING="${MISSING} ${I}"
  2645.     fi
  2646. done
  2647. if test "${MISSING}" = "" ; then
  2648.     echo You have unpacked all 11 archives.
  2649.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2650. else
  2651.     echo You still need to unpack the following archives:
  2652.     echo "        " ${MISSING}
  2653. fi
  2654. ##  End of shell archive.
  2655. exit 0
  2656. -- 
  2657. Rich $alz            rsalz@pineapple.bbn.com
  2658. Cronus Project, BBN Labs    "Anger is an energy"
  2659.